Reputation: 379
I'm using Windows 10 with VS2015 and Python 3.4. I have created a module called this.py
. Now I want to import this.py
. That works OK if this.py
is in the current folder. But I need this.py
to be in a different folder which is used by all of my scripts.
I have tried a few approaches but none would find this.py. One approach was to set my Windows CMD PATH.
Can someone tell me how to set the search path for imports?
Upvotes: 0
Views: 152
Reputation: 5172
You should do something like this:
import sys
sys.path.append("path-here")
Then that directory will be searched when you import something (other than standard directories)
Edit: the path of the directory containing the imported file, not of the file
Upvotes: 3