问题
I'm trying to change my PYTHONPATH. I've tried to change it in "My Computer" etc, but it doesn't exist there. I searched in the registry in some places, and even ran a whole search for the word 'PYTHONPATH', but to no avail.
However, it Python I can easily see it exists. So where is it?
回答1:
Python does some stuff up front when it is started, probably also setting that path in windows. Just set it and see, if it is changed in sys.path.
Setting environment variables in the Python docs say:
My Computer ‣ Properties ‣ Advanced ‣ Environment Variables
回答2:
At runtime, you can change it with:
import sys
sys.path.append('...')
In My Computer, right-click Properties (or press Win-Break), System tab, Environment Variables, System. You can add it if it's not already there.
Finally, in the CMD prompt:
set PYTHONPATH C:\Python25\Lib;C:\MyPythonLib
Or in bash:
PYTHONPATH=/usr/share/python/lib:/home/me/python
export PYTHONPATH
Or, more succinctly:
export PYTHONPATH=/home/me/python
回答3:
You can add it under "My Computer" if it doesn't exist. PYTHONPATH just adds to the default sys.path.
On unix/linux/osx you can:
$ export PYTHONPATH=/to/my/python/libs
You can also use .pth files to point to libraries:
http://docs.python.org/library/site.html#module-site
And of course:
import sys
sys.path.append('/path/to/libs/')
Also, check out virtualenv for managing libraries for multiple projects.
回答4:
Here's how I solved it.
First, get the current path. There's a lot more there than I expected.
import sys
print ';'.join(sys.path)
Copy that result to the clipboard. Go to My Computer and create the new environment variable PYTHONPATH, and for the value paste from the clipboard. Modify as necessary.
回答5:
MacOS 10.5.8, Python 2.6, Eclipse+Pydev 1.5.7
Python installation's site-package is, for example:
/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packagescreate symlinks YOUR LIBRARY inside into site-package, for example:
Now You can use in commandline:cd /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages ln -s /path/to/YOUR/LIBRARY/ YOUR_LIBRARY_NAMEimport YOUR_LIBRARY_NAMErun Eclipse with Pydev, go to Preferences->Pydev->Interpreter Python
remove Your Python interpreter record, if exists;
click New and add Python 2.6 interpreter path, for example:
/Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6notice, that Eclipse Pydev display Python System Library, accept that
in Library section click New Folder and write path to YOUR LIBRARY, for example:
/path/to/YOUR/LIBRARY/click Apply - it is essential, because Eclipse Pydev built now his own "library map", when this operation finish - click [OK]
close Eclipse
run Eclipse again - now You should use in Pydev:
import YOUR_LIBRARY_NAME
回答6:
And, as with all good things in life, you can find it in the documentation: http://docs.python.org/install/index.html#modifying-python-s-search-path
回答7:
What's it set to? Have you tried creating a PYTHONPATH environment variable?
回答8:
You need modify your environment variables. How to do this depends on which version of Windows you have.
If the PYTHONPATH variable doesn't exist, you have to create it. It might not exist if you haven't already created it.
来源:https://stackoverflow.com/questions/859594/cant-find-my-pythonpath