One, module, Package 1, module
The module is essentially a python file. It is used to organize the code, meaning to write the Python code inside, the filename is the name of the module, test.py test is the name of the module
2. Package
Packages, the package is essentially a folder, and unlike a folder it has a __init__.py file. The package is logically organized into modules, that is, it is used to store modules, if you think of a module in other directories, then this directory must be a package to be imported.
II. Module Classification 1, standard module, standard package
Python comes with these modules, which can be used directly by import.
Import String,random,datetime,os,sys,json,hashlib
2. Third-party modules
Others have written some modules, you have to install before you can use
Want to implement a function, you can first go to Baidu search for third-party modules
3, write their own Python file three, install a third-party module 1, fool-style
(1) Directly in command Line window Input command pip install Pymysql, pip install Redis
Pip in python3.4 or above is self-bringing. This way, however, you need to ensure that the project interpreter path in the pycharm is the Python installation path, or the import will not succeed even if the window displays a successful download installation
Because the command line is downloaded, the third-party installation package is stored in the Python installation path \python3\lib\site-packages
When Pycharm import, it is the path set from the Pycharm->file->settings->project interpreter-> \python\venv\lib\ Site-packages to pick up a third-party installation package
(2) You can also install the third-party module directly in the Pycharm, so that the installed module will be placed in the path under Project interpreter-> settings \python\venv\lib\site-packages, you can use directly.
(3) If you are prompted that the PIP command does not exist
Enter where Pip
If you are prompted that PIP is not an internal command
Pycharm External Libraries
Note: After Python 3.5, scripts automatically joins the computer environment variable
There's no PIP command.
A, pycharm inside dot python console
B. Find the Python installation directory
C, then put the scripts directory under the installation directory, add to the environment variable inside can
PS: Environment variables are added in path
(4) Unknown or unsupported command ' install ' out of this ask how to solve
A. Open C:\strawberry\perl\bin\
b, the list of the PIP is changed to other names, this has no effect on the other
2. Manual Installation
To restrict the extranet from being downloaded directly, you can find someone else to download the package and install it manually.
(1) Baidu search: Python Redis
(2) Find the URL: https://pypi.python.org/pypi/redis#downloads, download the installation package
(3) 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
(4) Install tar.gz end of installation package
A. Unzip the package
b, enter into the folder after the decompression (shift+ right click here to open the Command Line window (or in the Address bar directly enter CMD))
C. Run Python setup.py install on the command line
Iv. Import Module
1, the Order of Python import module:
(1) Find the Python file you want to import from the current directory
(2) Find sys.path from Python's environment variables
2, the essence of the import module:
is to execute the Python file one time from the beginning
As an example:
(1) Customizing a Python module dr.py, placed in the current directory
name = ' Hello ' def my (): print (' Python ') my ()
(2) Create a new tmp.py
Import Dr #导入文件的时候已经把python文件执行了一次, print out Pythonprint (dr.name) #打印出hellodr. my () #打印出python
The code above can also be written in the following way
From Dr Import name,my #这种调用自定义函数时不用再写 "file name. function", directly write function or variable name print (name) my ()
From Dr Import * #导入所有的 #from AA import *my () #尽量不要用 because it's hard to see which file the function belongs to when looking at the source code
(3) When the dr.py is placed under one of the SYS.PATH environment variables, Dr. Can point out a function.
(4) The current directory and the PATH environment variable are dr.py, will be preferred to select the current directory dr.py
Python Learning Note 10 _ modules, third-party module installation, module import