In this article, we'll share the 3 ways Python adds a module search path, without adding "Add default module search path for Python".
There are several ways to do this:
1, ADD environment variable Pythonpath,python Add the module under this path, add the following line in the. bashrc file:
Export pythonpath= $PYTHONPATH:/usr/local/lib/python2.7/site-packages
2, add a path configuration file under the Site-packages path, the file extension is. PTH, the content is the path to be added
3, the Sys.path.append () function adds a search path, and the parameter value is the path to add.
Find another article online
Add a default module search path for Python
Method One: Function add
1 Import sys
2 views Sys.path
3 Adding Sys.path.append ("c:\\")
Method Two: Modify environment variables
W user can modify system environment variable Pythonpath
Method Three: Add. pth files, recommended!
To add a path file in Site-packages, such as mypkpath.pth, you must use the. PTH suffix to write the directory name of the module file you want to add.
1 windows
C:\python27\site-packages
2 Linux (Ubuntu)
/usr/local/lib/python2.7/dist-packages
2 Linux (Redhat)
/usr/lib/python2.7/site-packages
Python Add module search path in Ubuntu