Python project for offline deployment


Installation package preparation: Download the required third-party library installation package under network conditions
1. Extract the third-party library directory to requirements.txt
2. Download the whl files of requirements.txt in batches
3. Possible problems
Summary
Start offline installation
and create virtual Environment
Install the library according to requirements.txt
Summary
Possible problems when starting the project from the command line

Installation package preparation: download the required third-party library installation package under network conditions

pip offline upgrade

python3 -m pip install --upgrade pip-23.0.1-py3-none-any.whl


1. Extract the third-party library directory to requirements.txt
pip freeze > requirements.txt
 

2. Download the whl file
packages of requirements.txt in batches: the directory name stored after downloading.
If the download speed is too slow, you can connect to Tsinghua mirror -i https://pypi.tuna.tsinghua.edu.cn/simple some-package
pip download -d packages -r requirements.txt

3. Possible problems
It may be necessary to support the pip version when installing certain libraries, and an error will be reported if the version is too low. It is recommended to download the latest version of the whl file of pip separately.
pip download -d packages pip

Summary
So far, all the third-party library installation files we need for offline deployment have been prepared.


Start offline installation

Install the library according to requirements.txt
In order to ensure a smooth installation, first perform a pip upgrade, and packages is the third-party library installation package path
pip install --upgrade pip --no-index -f packages

Batch installation
pip install -r requirements.txt --no-index -f packages

Check
pip freeze


Summary
So far the installation is successful

Problems that may occur when starting a project from the command line
If the project has multiple levels of directories, the directory may not be found when running. This is because the file is imported during project development, and the imported path is relative to the top-level directory path of the project.
Solution:
Add the following code at the top of the running file:
Note: The added path is the top-level directory path of the project, which can be changed according to your own project level.

import sys
import os
sys.path.append(os.path.abspath(os.path.join(os.getcwd(), "../..")))

Guess you like

Origin blog.csdn.net/GL666/article/details/129549264