In the current production environment , There's a lot based on python The developed tools need to use .
because python Tools often involve many dependencies , Online , Can pass pip requirements To manage the installation .
But sometimes , You will encounter the environment that needs to be deployed , Can't connect to pip Source situation . such as , The client is on the intranet or has no network connection .
under these circumstances , Prepare a completely offline installation environment , It can greatly reduce the cost of tool deployment .
In a project , Developed a windows Based on python Data display tool .
Suppose there is no environment on the customer's computer , The following steps summarize how to deploy offline .
Consider streamlining as much as possible , When the project is less dependent , It is recommended to use python Standard package deployment environment .
stay python Official website Or download from other sources python Install the package and install .
If the virtual environment is not isolated during development , You can isolate at this time .
Assume that the standard has been downloaded and installed Python package 3.8, And installed in D:/python3.8/
Get into CMD Command line
D:\python3.8\python.exe -m venv d:\virtual_env
Of course , If it's already configured Path The system variable of , Can directly
python.exe -m venv d:\virtual_env
After establishing a new environment , In the new environment d:\virtual_env
pip freeze > requirments_zero.txt
The result should be an empty file .
Activate the virtual environment ( Switch pycharm Of interpreter perhaps active A virtual environment )
Now , The package required for the new project is not installed , Can't run .
For projects that have been developed , One should have been recorded requirements.txt, for instance , This project relies on :
( The following is a requirements.txt)
flask
flask-cors
paramiko
pyecharts
piexif
this 5 Line has been recorded in requirements.txt in
Can pass
pip install -r requirements.txt
install
If there is no record , You need to check and install the dependent libraries one by one
When the project can run normally in the new environment , In the new environment d:\virtual_env Next
pip freeze > requirments_full.txt
Will generate a containing based on the current python List of all dependency chains of version , for instance , This project relies on :
( The following is a requirements_full.txt)
bcrypt3.2.0
cffi1.15.0
click8.0.3
colorama0.4.4
cryptography36.0.1
Flask2.0.2
Flask-Cors3.0.10
itsdangerous2.0.1
Jinja23.0.3
MarkupSafe2.0.1
paramiko2.9.2
piexif1.1.3
prettytable3.0.0
pycparser2.21
pyecharts1.9.1
PyNaCl1.5.0
simplejson3.17.6
six1.16.0
wcwidth0.2.5
Werkzeug2.0.3
By the following command , Sure
pip download -r requirements_full.txt -d ./packages
after 1~5 Step , I've got :
Copy python Installation package 、requirements.txt and packages
pip install --no-index --find-links=./packages -r requirements.txt