How to view the path of a Python search package:
The path to the Python search package is stored under Sys.path
View Method:
Import Sys
Sys.path
How to temporarily add a Python search package path:
Method 1: (enter Python first) import sys
Sys.path.append (' path ')
(This approach is only valid for current Python)
Method 2:
Export pythonpath= Path
(This way works for all Python)
Ways to permanently write Sys.path:
Method 1: Add the. pth file under an existing Sys.path search path, and the file content format is:
Import site; Site.addsitedir ("/usr/local/lib/python2.7/site-packages")
Method 2:
Add the following line to the. bash_profile file in the home folder:
Export pythonpath= Path
Note that Sys.path values are different after you start a different Python, for example:
The python under Startup Conda is the Sys.path value
[
'',
'/users/zj_macbook/anaconda/lib/python27.zip ',
'/users/zj_macbook/anaconda/lib/python2.7 ',
'/users/zj_macbook/anaconda/lib/python2.7/plat-darwin ',
'/users/zj_macbook/anaconda/lib/python2.7/plat-mac ',
'/users/zj_macbook/anaconda/lib/python2.7/plat-mac/lib-scriptpackages ',
'/users/zj_macbook/anaconda/lib/python2.7/lib-tk ',
'/users/zj_macbook/anaconda/lib/python2.7/lib-old ',
'/users/zj_macbook/anaconda/lib/python2.7/lib-dynload ',
'/users/zj_macbook/anaconda/lib/python2.7/site-packages ',
'/users/zj_macbook/anaconda/lib/python2.7/site-packages/sphinx-1.4.6-py2.7.egg ',
'/users/zj_macbook/anaconda/lib/python2.7/site-packages/aeosa ',
'/users/zj_macbook/anaconda/lib/python2.7/site-packages/setuptools-27.2.0-py2.7.egg '
]
Start
/system/library/frameworks/python.framework/versions/2.7/bin/python
The value of the Python Sys.path
[
'',
'/usr/local/lib/python2.7/site-packages/six-1.10.0-py2.7.egg ',
'/library/python/2.7/site-packages/twilio-6.3.dev0-py2.7.egg ',
'/library/python/2.7/site-packages/httplib2-0.9.2-py2.7.egg ',
'/system/library/frameworks/python.framework/versions/2.7/lib/python27.zip ',
'/system/library/frameworks/python.framework/versions/2.7/lib/python2.7 ',
'/system/library/frameworks/python.framework/versions/2.7/lib/python2.7/plat-darwin ',
'/system/library/frameworks/python.framework/versions/2.7/lib/python2.7/plat-mac ',
'/system/library/frameworks/python.framework/versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages ',
'/system/library/frameworks/python.framework/versions/2.7/lib/python2.7/lib-tk ',
'/system/library/frameworks/python.framework/versions/2.7/lib/python2.7/lib-old ',
'/system/library/frameworks/python.framework/versions/2.7/lib/python2.7/lib-dynload ',
'/users/zj_macbook/library/python/2.7/lib/python/site-packages ',
'/usr/local/lib/python2.7/site-packages ',
'/usr/local/cellar/numpy/1.12.0/libexec/nose/lib/python2.7/site-packages ',
'/usr/local/cellar/protobuf/3.2.0/libexec/lib/python2.7/site-packages ',
'/library/python/2.7/site-packages ',
'/system/library/frameworks/python.framework/versions/2.7/extras/lib/python ',
'/SYSTEM/LIBRARY/FRAMEWORKS/PYTHON.FRAMEWORK/VERSIONS/2.7/EXTRAS/LIB/PYTHON/PYOBJC '
]