程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Completed Python project - environment offline deployment

編輯:Python

python Environment offline deployment

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 .

preparation

1. Prepare clean Python package

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 .

2. Create a python Virtual environment for

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 .

3. The dependencies needed to install this project in the virtual environment , Until the project can run

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

4. Generate requirements.txt

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
cffi
1.15.0
click8.0.3
colorama
0.4.4
cryptography36.0.1
Flask
2.0.2
Flask-Cors3.0.10
itsdangerous
2.0.1
Jinja23.0.3
MarkupSafe
2.0.1
paramiko2.9.2
piexif
1.1.3
prettytable3.0.0
pycparser
2.21
pyecharts1.9.1
PyNaCl
1.5.0
simplejson3.17.6
six
1.16.0
wcwidth0.2.5
Werkzeug
2.0.3

5. Download all of the dependency chain whl

By the following command , Sure

pip download -r requirements_full.txt -d ./packages

after 1~5 Step , I've got :

    1. python Installation package
  • 2 requirements_full.txt
  • 3 packages/ Folder
    this 3 Data can be found in other PC Deploy online and offline python Environmental Science

New environment deployment

Copy python Installation package 、requirements.txt and packages

  1. install python
  2. Once installed , Go to the command line , Enter the following command to install offline packages
pip install --no-index --find-links=./packages -r requirements.txt

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved