I've written a library in python and I want it to reside in a common location on the file system.
From my script, I just want to do:
>>> import mylib
Now I understand that in order to do this, I can do this:
>>> import sys
>>> sys.path.append(r'C:\MyFolder\MySubFolder')
>>> import mylib
But I don't want to have to do that every time.
The question is: How do I add a folder to python's sys.path permanently? I would imagine that it would be an environment variable, but I can't find it.
It seems like it should be easy, but I can't find out how to do it.
On each line of the file you put one directory name, so you can put a line in there with /path/to/the/ and it will add that directory to the path. You could also use the PYTHONPATH environment variable, which is like the system PATH variable but contains directories that will be added to sys. path .
Python3. Output: APPENDING PATH- append() is a built-in function of sys module that can be used with path variable to add a specific path for interpreter to search.
Now, you should be able to call python from the command line directly. The next time you log in, Python should automatically be added to PATH .
The PYTHONPATH environment variable will do it.
Deducing from the path you provided in your example here's a tutorial for setting the PYTHONPATH variable in Windows: http://docs.python.org/using/windows.html#excursus-setting-environment-variables
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