The path to the Python search package

Source: Internet
Author: User
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 '
]







Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.