As shown in the title , use Python The goal may not be to write code , Instead, use some open source libraries or some that need to be used Python Software for . If not a programmer or right Python Not familiar with , It will be very troublesome . Tell the truth , Personally feel python The module installation of is very difficult to use , The main problems are the version and download , For Xiaobai or unfamiliar python For people who , It's still a bit of a hassle , This article is to solve this problem , Hope to make python The process of installing the plug-in becomes simpler . And through examples to illustrate .
Starting with the installation .
Download the corresponding version from the official website .
I downloaded it Windows Of 3.9.9 edition .macos It's the same if you want to .Linux There is no installation package for version , One is because Linux System comes with python, Two is Linux There are a lot of releases .
https://www.python.org/downloads/windows/
https://www.python.org/downloads/macos/
Click Start installation :
In the first interface, check both of the following ,Add Python to PATH Option automatically configures environment variables . And then we click Customize installation Start custom installation .
Tick all the next steps .
Set to the following , The installation position can be selected by yourself , Whatever you like , Path cannot have Chinese name . Path characters cannot exceed 260 Characters .
Click on the install . Seeing this interface indicates success .
Press keyboard win and r key , Input cmd. Enter to call out cmd window . Input python If the following content appears, the installation is successful .
Here is an example to illustrate Python Module installation .
Python A powerful feature is that it supports many modules . Modules need to be installed by themselves , This is a difficult place . Can pass pip list Command to view the installed modules , By default , Only the following two modules ,pip The command itself is also a module .
C:\Users\Administrator>pip list
Package Version
---------- -------
pip 21.2.4
setuptools 58.1.0
WARNING: You are using pip version 21.2.4; however, version 22.1.2 is available.
You should consider upgrading via the 'E:\softsInstaller\python\python.exe -m pip install --upgrade pip' command.
Before installing the module, you need to configure the domestic image , because python Modules are placed on the Internet , Direct installation has little speed .
Use the following command to open source installation numpy This module , But the speed is very slow .
pip install numpy
You can add a mirror in the following way .
1、 Temporary use add to -i Parameters can be
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple numpy
2、 Permanent modification
pip config --global set global.index-url https://mirrors.aliyun.com/pypi/simple/
Then use it directly pip install xxx It can be installed at full speed .
The following paragraph is a detailed description , You can choose .
The above order will be in pip Configuration file for ( If there is no such file, it will be created automatically ) The following configuration fragments are automatically generated in :
pip.ini( stay Unix and MacOS It's called on the platform pip.conf)
therefore , You can also manually pip Add the above configuration fragment to the configuration file of . If the corresponding configuration file does not exist , You can create it yourself :
stay Unix In the system , The profile is located in /etc/pip.conf. Besides , It can also be located in an environment variable of XDG_CONFIG_DIRS Of any path pip Subdirectory , for example :/etc/xdg/pip/pip.conf.
stay MacOS In the system , The file is located at :/Library/ApplicationSupport/pip/pip.conf
stay Windows XP In the system , The file is located at :C:\Documentsand Settings\All Users\Application Data\pip\pip.ini
stay Windows 7 And above , This file is hidden by default , The actual location is :C:\ProgramData\pip\pip.ini
You can also use a named PIP_CONFIG_FILE Configure the specific file path in the environment variable of .
pip.ini file :
[global]
index-url = https://mirrors.aliyun.com/pypi/simple/
If there is no error, the installation is successful . use pip list see .
C:\Users\Administrator>pip list
Package Version
---------- -------
numpy 1.22.4
pip 21.2.4
setuptools 58.1.0
Install the latest version by default , occasionally , There may be special requirements for the version , You can specify the version at this time .
pip install numpy=1.22.0
Mass installation :
With a very famous DeepFaceLab Software, for example , This software requires a lot of modules , In general , The software will tell you what modules you need to install , And write the module name and version in a file called requirements.txt In the document of , This file name is freely available , It usually looks like the following .
python Provide commands to support batch installation . Use the following command to batch install modules .
pip install -r requirements.txt
I've finished with pip Install the module .pip It's just python Just a tool provided by , The subject is still python In itself . commonly python The suffix of the source code is .py. Generally, open source programs provide main.py perhaps setup.py. You can execute the source code through commands to start the program , The prerequisite is that the required modules have been installed .
python main.py