How do I add a path "permanent" to Sys.path?
Sys.path is the path set of the Python search module, a list
Copy Code code as follows:
[', ' c:\\windows\\system32\\python26.zip ', ' c:\\python26\\dlls ', ' c:\\python26\ \lib ', ' c:\\python26\\lib\\ Plat-win ', ' c:\\python26\\lib\\lib-tk ', ' c:\\python26 ', ' c:\\python26\\lib\\site-packages ', ' C:\\Python26\\lib\\ Site-packages\\win32 ', ' c:\\python26\\lib\\site-packages\\win32\\lib ', ' C:\\python26\\lib\\site-packa ges\\ Pythonwin ']
You can use Sys.path.append (path) to add related paths in a Python environment, but the path you add yourself after exiting the Python environment automatically disappears!
Modifying in a Python script
Copy Code code as follows:
Import Sys
Sys.path.append (' C:\\mypythonlib ')
To solve this problem, you can have the following methods:
1. Place your own py file in the Site_packages directory:
The following command shows the Site-packages directory:
Copy Code code as follows:
Python-c "from distutils.sysconfig import get_python_lib; Print Get_python_lib () "
But doing so can lead to the problem that all kinds of modules are put into this folder, which can lead to chaos, which is obvious.
Note that you do not create subfolders and then place your own modules in a subfolder to resolve the problem, which can cause errors when you use the import statement.
2. Use the PTH file, create a. pth file in the Site-packages file, write the path of the module, a line of paths, the following is an example, the PTH file can also use the annotation:
#. pth file for the My project (this line is a comment)
E:\DjangoWord
E:\DjangoWord\mysite
E:\DjangoWord\mysite\polls
This is a good idea, but there are administrative problems and cannot be shared in different versions of Python.
3. Using the PYTHONPATH environment variable, enter the relevant path in this environment variable, with a comma between the different paths (English!). Apart, if the Pythonpath variable does not exist, you can create it!
Paths are automatically added to the Sys.path and can be shared in different versions of Python, which should be the easiest way to do it.
For information about the environment variables associated with Python, please refer to:
Http://docs.python.org/using/cmdline.html
Find Pythonpath on the page