Python project collaborative development of VScode/PyCharm+Anaconda+pyQt5 (environment construction and project configuration)

1. Background

        The previous application of python has been stuck at the stage of writing a main function, writing a piece of logic, and completing a purpose. I don’t know what the reader’s learning route is?

        As for the establishment of the python environment, the individual has actually gone through the following stages:

① During the early contact, download and install from the python official website, complete the configuration of environment variables, write the running script in the SublimeText editor, and use CMD to call .py in the production environment;

②After that, to save trouble, install and configure directly in the integrated IDE such as VisualStudio, and install the python plug-in in VScode for use; more is to install PyCharm, configure the interpreter to build the environment.


         It can be seen that the use of python before writing this article is extremely simple. It is understood as commands such as dos and sh, and only script functions similar to batch processing are used in use.

        Recently, I took over a small python interface program developed by other colleagues based on the pyQt5 module, and learned something new about Anaconda when building the environment; and for projects, and projects that require collaborative development, it is not only a collection of several .py scripts, but also things related to IDEs, version management tools such as git, etc., so there is this article.

2. Personal summary

A few points are summarized:

①The correct way is that a python project corresponds to a virtual environment, instead of putting all the packages together, this is what python distributions like anaconda do (it can be created with venv or managed by conda, as for how many other virtual environments there are, you can refer to the list of python interpreter interfaces for projects in pycharm).

②The virtual environment cannot be reused. On multiple development PCs and multiple production PCs, packages can be reused (refer to the following, realize package reuse through requirements.txt and whl folders)

③Developers need to consider which files to git version control ; in view of the experience of C# projects in ViusalStudio, nuget is a package management tool similar to pip and conda, which can be obtained directly from pip without uploading to git. Unless you have your own modification on the open source code, you still need to upload the modified code.


Some nouns encountered when editing this article, and their simple understanding are as follows:

【.idea】

General engineering configuration files for jetbrains software tools such as pycharm.

【.idea-workspace.xml】

Personal development environment configuration does not require version management. If you want to manage it, you need to modify <option name="SDK_HOME" value="your python.exe path" to the path corresponding to the correct python interpreter in the development environment for reuse.

【anaconda】

A python distribution software that can configure virtual environments for multiple python projects.

【venv、virtualenv】

The former is a subset of the latter. After Python3.6, the standard library comes with a venv virtual environment, and the virtual environment cannot be transplanted (see warning:

venv — Create a virtual environment — Python 3.10.8 documentation
 

Virtualenv — virtualenv 20.16.6.dev4+gcdf4225 documentation (pypa.io)

PEP 405 - Python Virtual Environments | peps.python.org )

【venv-pyvenv.cfg】

Virtual environment configuration, in the default configuration, home points to the directory where the python interpreter that created the venv is located, and is generated by default when using python -m venv your_venv to create a new environment.

【requirements.txt】

① Export, use pip freeze > requirements.txt in the activated venv to export the package to txt;

② Import the new environment, create a new venv, activate, copy the txt exported above to the Scripts directory, and use the following instructions to install from the txt

pip install -r requirements.txt  -i Simple Index --trusted-host mirrors.aliyun.com

(F7 in CMD to view historical commands, F9 can enter the serial number of historical commands to jump to this command)

【requirements.txt + packages】

Prerequisite: The package list has been exported to txt through pip freeze > requirements.txt

①Download whl to the packages folder

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

② Copy the packages folder, requirements.txt to the new environment, and install whl offline (the premise is that venv has been created in the new environment, which is also applicable to the conda environment, just copy it to the directory where python.exe is located in the conda environment)

pip install --no-index --find-links=./packages -r requirements.txt

Guess you like

Origin blog.csdn.net/qq_23958061/article/details/127450565