Python Add module path

Source: Internet
Author: User

 1, adding temporarily with a function
1  Import sys                    # importing sys module 234 sys.path.append (R'  /tmp/test')    # to use absolute path 5print(sys.path)        # View Module Path

2, add it permanently, add it in the third-party module directory. PTHsuffix name file

Ubuntu The third-party module directory is named: dist-packages

Windows and the Redhat The third-party module directory is named: site-packages

Test Example:2.1Createtest.pyfile that is used to view the currentpythonModule Path
cat >>test.py<<eofimport sysprint (sys.path) EOFcat test.py

2.2 Viewing the current Python module path
Python test.py

2.3 Adding a module path

The third-party module directory path here is:/usr/lib/python2.6/site-packages

The module path to add is:/tmp/test/

mkdir -p/tmp/testecho"/tmp/test/">/usr/lib/python2. 6/site-packages/mytest.pthcat /usr/lib/python2. 6/site-packages/mytest.pth

2.4 Verify success or not
Python test.py

Success!!!

Python Add module path

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.