Python Import search path path setting Pythonpath Library

Source: Internet
Author: User

Overview of importing Python import

The module name in an import statement has two functions: the identification of the loaded external document will also be assigned to the variable loaded into the module, the module-defined object will also be created at execution time, when the import is executed, Import will run the statements in the target document one at a time to establish the contents of the


  1. find module file
  2. compiled into a bit code (if required)
  3. Execute the code of the module to create the object it defines

These three steps only when the program executes,

When the module is first imported, when the same module is imported, the three steps are skipped, but only the module objects loaded in memory are extracted

Import Search Path


  • The program's home directory

Hello I am coming

(' FDADF ', ' FASDFASD ')

[' D:\\Program project\\python Project ', ' c:\\windows\\system32\\python27.zip ', ' c:\\python27\\dlls ', ' C:\\Python27\ \lib ', ' C:\\python27\\lib\\plat-win ', ' c:\\python27\\lib\\lib-tk ', ' c:\\python27 ', ' c:\\python27\\lib\\ Site-packages ']

The directory that contains the program:d: \\Program project\\python Project '


    • The Pythonpath directory (if set):p Ython searches from left to right for all directories listed in the PYTHONPATH environment variable settings, in short, Pythonpath is a list of directories that contain Python program files. These directories can be user-defined or platform-specific directory names

Detailed settings See: http://blog.csdn.net/fyh2003/article/details/6837624

Because Python searches the home directory first, this setting is important when importing files across directories


    • Standard link Library Directory

Python then automatically searches those directories that the standard library module installs on the machine, as these are bound to be searched, so there is no need to add them to the Pythonpath.

    • the contents of any. pth file (if present) allows the user to add a valid directory to the module search path, that is, a text file with the suffix. PTH that lists the directories in a row, you can place a. path file on the top level of the Python installation directory (for example, C:\Python27) to expand the module search path. At this time can play the role of Pythonpath,
other

  • Sys.path: Is the path to the module search, Python is configured at program startup, automatically merges the path setting values of the Pythonpath and. path files into this list, and sets the first entry as the home directory for the top-level file
  • Third-party extensions in Python are typically installed automatically using the Distutils tool in the standard link library, so you can use their code without the need for path settings

Python Import search path path setting Pythonpath Library

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.