Whenever I use sys.path.append
, the new directory will be added. However, once I close python, the list will revert to the previous (default?) values. How do I permanently add a directory to PYTHONPATH
?
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
If you're using bash (on a Mac or GNU/Linux distro), add this to your
~/.bashrc
For me it worked when I changed the
.bash_profile
file. Just changing.bashrc
file worked only till I restarted the shell.For python 2.7 it should look like:
at the end of the
.bash_profile
file.I added permanently in Windows Vista, Python 3.5
System > Control Panel > Advanced system settings > Advanced (tap) Environment Variables > System variables > (if you don't see PYTHONPATH in Variable column) (click) New > Variable name: PYTHONPATH > Variable value:
Please, write the directory in the Variable value. It is details of Blue Peppers' answer.
You need to add your new directory to the environment variable
PYTHONPATH
, separated by a colon from previous contents thereof. In any form of Unix, you can do that in a startup script appropriate to whatever shell you're using (.profile
or whatever, depending on your favorite shell) with a command which, again, depends on the shell in question; in Windows, you can do it through the system GUI for the purpose.superuser.com
may be a better place to ask further, i.e. for more details if you need specifics about how to enrich an environment variable in your chosen platform and shell, since it's not really a programming question per se.Adding
export PYTHONPATH="${PYTHONPATH}:/my/other/path"
to the ~/.bashrc might not work ifPYTHONPATH
does not currently exist (because of the:
).Adding the above to my ~/.bashrc did the trick for me on Ubuntu 16.04
This works on Windows
Then you'll be able to see all modules within those paths from your scripts.