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
- find module file
- compiled into a bit code (if required)
- 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