1.1 Mounting Module1.1.1 installing third-party modules
The third-party library will be Python official pypi.python.org website registration, to install a third-party library, you must first know the name of the library, you can search on the official website or PyPI , such as Pillow name called Pillow
Pip Install Pillow
1.1.2 Module Search Path
when we try to load a module, Python searches for the corresponding. py file under the specified path , and if it does not, it will get an error:
>>> Import MyModule
Traceback (most recent):
File "<stdin>", line 1, in <module>
Importerror:no module named MyModule
by default, The Python interpreter searches the current directory , all installed built-in modules, and third-party modules , and the search path is stored in the PATH variable of the SYS module :
>>> Import Sys
>>> Sys.path
[' ', '/library/frameworks/python.framework/versions/3.4/lib/python34.zip ', '/library/frameworks/python.framework /versions/3.4/lib/python3.4 ', '/library/frameworks/python.framework/versions/3.4/lib/python3.4/plat-darwin ', '/ Library/frameworks/python.framework/versions/3.4/lib/python3.4/lib-dynload ', '/library/frameworks/ Python.framework/versions/3.4/lib/python3.4/site-packages ']
If we want to add our own search directory, there are two ways:
one is to modify the Sys.path directlyand add the directories to be searched:
>>> Import Sys
>>> sys.path.append ('/users/michael/my_py_scripts ')
This method is modified at run time and is invalidated after the run is finished.
the second method is to set the environment variable PYTHONPATH, the contents of the environment variable are automatically added to the module search path. Settings are similar to setting the Path environment variable. Note that you only need to add your own search path, andPython 's own search path will not be affected.
This article is from the "90SirDB" blog, be sure to keep this source http://90sirdb.blog.51cto.com/8713279/1821050
Python Installation Module & Module Search path