How can I find out which path os.path points to?

Question:

i am a web developer (php, js, css and …).
i order a python script for remove image background. it worked in cmd very well but when running it from php script, it dosnt work.
i look at the script for find problem and i realized that the script stops at this line:

net.load_state_dict(self.torch.load(os.path.join("../library/removeBG/models/", name, name + '.pth'), map_location="cpu"))

I guess the problem with the script is that it can’t find the file, and probably the problem is caused by the path that os.path points to.
Is it possible to print the path that os .path points to?
If not, do you have a solution to this problem?

Asked By: babak-maziar

||

Answers:

The problem here is that the php script might be in different directory so while executing the python script via php script, the os.path points to the directory from where it is being executed i.e. the location of php script.

TLDR; Try using absolute path.

Answered By: GauravGiri

This should be enough:

name = 'name'
p = os.path.join("../library/removeBG/models/", name, name + '.pth')
print(p)

This is what i get:

>>> ../library/removeBG/models/name/name.pth
Answered By: Leno
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.