python virtual environment management

Introduction

In Python, a virtual environment is a tool used to isolate different projects. It can help you maintain an independent Python environment in each project, so as to manage the libraries and package versions that the project depends on.

use

virtualenv

This is the virtual environment management tool officially recommended by Python. You can create and activate a virtual environment with the following commands:

$ pip install virtualenv
$ virtualenv <env_name>        # 创建一个虚拟环境
$ source <env_name>/bin/activate     # 激活虚拟环境 (对于在Unix或Linux上)
$ .\<env_name>\Scripts\activate     # 激活虚拟环境 (对于在Windows上)

venv

This is a virtual environment management tool built into Python 3.3 and above. You can create and activate a virtual environment with the following commands:

$ python3 -m venv <env_name>        # 创建一个虚拟环境
$ source <env_name>/bin/activate     # 激活虚拟环境 (对于在Unix或Linux上)
$ .\<env_name>\Scripts\activate     # 激活虚拟环境 (对于在Windows上)

conda

This is a popular Python package manager and virtual environment management tool mainly used for scientific computing and data science projects. You can create and activate a virtual environment with the following commands:

$ conda create --name <env_name>        # 创建一个虚拟环境
$ conda activate <env_name>     # 激活虚拟环境

pipenv

This is a tool for Python project management and virtual environment management that combines the functionality of pip and virtualenv. You can create and activate a virtual environment with the following commands:

$ pip install pipenv
$ pipenv --python <python_version>        # 创建一个虚拟环境
$ pipenv shell     # 激活虚拟环境

The above are some common Python virtual environment management tools and their basic usage. You can choose the right tool to manage your virtual environment according to your personal preferences and project needs

Guess you like

Origin blog.csdn.net/dreams_dream/article/details/131845037