One, Module & package
1. Module
A module is essentially a Python file, which is used to organize your code. This means that the Python code is written in, and the filename is the name of the module. For example: Random.py,random is the name of the module.
2. Package
The package is also called Pageage, the essence is a folder, and the folder is not the same place is it has a __init__.py file. A package is a logical form of organizing a module, which means it is used to store modules. If you want to import a module from another directory, this directory must be a package to import.
Second, the classification of the module
1, standard module, standard package
Python comes with a standard module that can be used with direct import
Example: Import String,random,datatime,json,os, etc.
2. Third-party modules
Others have written some modules that need to be installed to use.
Want to implement a function, you can first use Baidu search for a third-party module
3. python files written by yourself
Iii. installation of third-party modules
1, the Fool-style
(1) Direct input in command-line window: Pip install pymysql (Python added environment variable)
Pip in Python3.4 or above is self-bringing. This way, however, you need to ensure that the project interpreter path in Pycharm is the Python installation path, or the import will not succeed even if the window displays a successful download installation. Because the third-party packages downloaded in the command window are stored under the Python installation path \python3\lib\site-packages, and Pycharm import is from Pycharm→file→settings→project interpreter→ set the path under \python\python36\lib\site-packages to fetch the third-party installation package.
(2) If the "pip command does not exist" prompt
Add the path to the script directory under the Python installation directory to the environment variable and execute the PIP command
(3) If prompted "Unknown or unsupported command ' install '"
A. Open C:\strawberry\perl\bin\
B. Change the PIP in this directory to another name
(4) You can also install the third-party module directly in the Pycharm, so that the installed module directly in the project interpreter→ set path under \python\python36\lib\site-packages, you can directly use
Such as:
2. Manual Installation
(1) Install WHL end of installation package
shift+ Right-click here to open a command-line window (or enter CMD directly in the Address bar)
Pip Install REDIS-2.10.6-PY2.PY3-NONE-ANY.WHL
(2) Install tar.gz end of installation package
A. Unzip the installation package
b, enter into the folder after the decompression
C, enter in the command line: Python setup.py install
3. Unloading module
Pip Uninstall Pymysql
Iv. sequence and substance of module import
1. The order in which the Python module is imported
(1) Search from the current directory
(2) Find from the python environment variable
2, the essence of the import module
Execute the python file from beginning to end
3. Import the Python file (module) in the current directory
(1) The first way:
1 Import Test 2 a = Test.name # Call the name variable in the test file 3 test.my () # Call the My () function in the test file
(2) The second way
1 from Import My,name 2 A = name # Call the name variable 3 my () # Call my function
4. Import python files (modules) from other directories
(1) Add the directory of the Python file (module) to the environment variable first
1 # First, add the directory to the environment variable and then import 2 Import SYS 3 sys.path.insert (0,'E:\Python\Script') # inserted at the front of the environment variable, high efficiency
(2) Importing Python files (modules)
1 Import Test # importing Test module 2 a = name # calling the name variable 3 My () # Call my function
When the same file is present under the current directory and under the environment variable, the files in the current directory will be selected first.
Python Learning ==> installation of third-party modules, module import