Server Deployment Python Project Summary


title: Server Deployment Python Project Summary
date: 2023-07-05 16:33:49
tags:

  • server
  • Python
    categories:
  • Server
    cover: https://cover.png
    feature: false

1. Prepare

The Python project requires a Python environment. If the server operating system is CentOS 7, Python2 and Python3 are installed by default. The corresponding commands are and python, python3including the corresponding pip commands . No additional installation of the Python environment is requiredpippip3

The environment installation is not explained here

2. Package project

Run in the project directory pip3 freeze >requirements.txtto generate the dependency list file required by the project

Then upload the project and the generated requirements.txt file to the server

3. Virtual environment

Generally, each different project will depend on its own library, and some library versions will cause conflicts. In order to solve this problem, you need to use a virtual environment. Python can create its own virtual environment in each project directory. The packages that the project depends on are in the current directory environment, which avoids library version conflicts and facilitates rapid copying of projects between the same operating systems.

1. First install the virtual environment,pip3 install virtualenv

2. Then execute in the project directory virtualenv venv --python=python3.6to create a virtual environment

3. Enable the virtual environment, source ./venv/bin/activate, the exit command is deactivate, delete the virtual environment and delete the folder

4. Install the library in the dependency list, pip3 install -r requirements.txt, due to other reasons such as network or version, an error may be reported, and it can be executed pip3 install --upgrade 依赖名for a single installation

5. pip3 list, to list the dependent libraries installed in the current virtual environment

6. Run the Python file in the background, nohup python xxx.py &, here I use nohup to support the background operation, and other methods can also be used

Guess you like

Origin blog.csdn.net/ACE_U_005A/article/details/131768995