During the course of my python program, I have generated the following string
"D:\something_else.py"
Lets say there are other resources in D: that something_else.py requires.
How would I go about running something_else.py from my code, which let's say is being run from C:\Users\Someone\Desktop?
Right now I'm using the following:
from subprocess import call
call(["python",pythloc])
This gives me an error as it's able to find only something_else.py and is unable to find the other resources that something_else.py needs which are in the same folder as something_else.py
Besides the fact that you need to be careful with "\" and instead of :
locationDir="D:\something_else.py"
prepend your string with r:
locationDir=r"D:\something_else.py"
you can simply set the PYTHONPATH environment variable to point to the directory in which sit the other modules.
See here for additional informations :
https://docs.python.org/3/using/cmdline.html#envvar-PYTHONPATH
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With