This article details Pythonsys. path. if you need it, you can refer to how to add the path "permanent" to sys. path?
Sys. path is the path set of the python Search module and is a list
The code is as follows:
['', 'C: \ WINDOWS \ system32 \ python26.zip ', 'C: \ Python26 \ DLLs', 'C: \ Python26 \ lib ', 'C: \ Python26 \ lib \ plat-win', 'C: \ Python26 \ 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 the python Environment. However, after exiting the python environment, the paths you add automatically disappear!
Modify in python script
The code is as follows:
Import sys
Sys. path. append ('C: \ mypythonlib ')
To solve this problem, you can use the following methods:
1. put your own py file in the site_packages Directory:
The following command displays the site-packages directory:
The code is as follows:
Python-c "from distutils. sysconfig import get_python_lib; print get_python_lib ()"
However, this will cause a problem, that is, if all the modules are placed in this folder, it will lead to chaos, which is obvious.
Note: If you do not create a subfolder, place your modules in the subfolder to solve the problem. this will cause an error when using the import statement.
2. use the pth file, create a. pth file in the site-packages file, write the path of the module into it, and create a path in one line. The following is an example. you can also use annotations for the pth file:
#. Pth file for the my project (this line is a comment)
E: \ DjangoWord
E: \ DjangoWord \ mysite
E: \ DjangoWord \ mysite \ polls
This is a good method, but there are management problems and cannot be shared in different python versions.
3. use the PYTHONPATH environment variable and enter related paths in this environment variable. separate paths with commas !) Separated. if the PYTHONPATH variable does not exist, you can create it!
The path is automatically added to sys. path and can be shared in different python versions. it should be the same convenient method.
For python-related environment variables, see:
Http://docs.python.org/using/cmdline.html
Find PYTHONPATH on the page