I had a file called example_file.py
, which I wanted to use from various other files, so I decided to add example_file.py
to sys.path
and import this file in another file to use the file. To do so, I ran the following in IPython.
import sys
sys.path
sys.path.append('/path/to/the/example_file.py')
print(sys.path)
I could see the path I had just added, and when I tried to import this file from another directory path like this:
import example_file
it worked just fine, but once I came out of IPython, entered it again, and checked the sys.path
, I saw that the path which I had added was not present, so how do I add a path to sys.path permanently in Python?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…