I. Definition and type of module
1. Definition
A module is a collection of code that implements some function with a bunch of code, usually one or more functions are written in a. py file, and if some features are complex to implement, then you need to create N. py files, and the collection of N. py files is a module
2. Type
1) custom modules, write your own. py file collection that implements some of your own functional requirements
2) Imported Modules
After you install Python, its own internal Lib file There are many modules can be used, after import can be used, usually the path is C:\Python27\Lib (27 is the version number, if the 3.5 version is C:\Python35\Lib)
3) Third party open source module
Third-party open source modules usually need to be downloaded by themselves, as illustrated by Linux and Windows systems.
Under Linux system
1 # Download and install Pycrypto 2 3 wget http://files.cnblogs.com/files/wupeiqi/pycrypto-2.6.1. tar.gz 4 5 TAR-XVF pycrypto-2.6.1. tar.gz 6 7 cd pycrypto-2.6.1 8 9python setup.py build python setup.py install
View Code
Under Windows system
1. Set the environment variables for Python a. Control panel-System and security-system-Advanced system settings-environment variables-system variable-PATHB. Add the Python installation directory to the inside, mine is C:\Python352. Download the module you need and unzip it, There are setup.py files in it. 3. Open cmd (Command prompt), switch to the directory of the decompression Module 4. Run the command: 1, setup.py Build-and 2, setup.py install5. Reopen the Python IDE, import module name, Installation is successful without error
or switch directly to the C:\Python35\Lib\site-packages directory to install
Use PIP3 install XXX (module name to install) then it will download it by itself, very simple
Ii. How to import a python module
Mainly include the following methods of import:
1, Import moduels (module name) #导入整个模块, this way of importing more memory
2, Import moduels (module name) as XX #这里是导入整个模块的同时给它取一个别名, because some of the module name is longer, with an abbreviated alias instead of the next time to use it is more convenient
3, from modules (module name) import func (method) #从一个模块里导入方法, you need to use the module in what method to import the method from that module, so that the memory is less
can also be represented by aliases: from modules (module name) import func (method) as XX
4, from Package.modules import func (method) #从一个包的模块里导入方法 This method is the same as the above, the memory consumption is relatively small
can also be represented by an alias, from modules (module name) import func (method) as XX
There are many modules used in Python, here are some common modules
Introduction to Python modules and modules