Python Add module search path in Ubuntu

Source: Internet
Author: User

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

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.