Home > Software engineering >  How can I find out which path os.path points to?
How can I find out which path os.path points to?

Time:12-03

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?

CodePudding user response:

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

CodePudding user response:

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.

  • Related