Installation and use of Python's virtualenv tool

Installation and use of Python's virtualenv tool

This article introduces the installation and use of Python's virtualenv tool in windows 10.

virtualenv allows you to create a local standalone python installation by cloning from an existing installation. Virtualenv is a virtual environment builder for python. Its main function is to create an independent python development environment. Different development environments are independent of each other and do not affect each other; allow different python development environments to use different components and versions. Official website: https://virtualenv.pypa.io/en/stable/

Virtualenv is a virtual environment builder for python. In python development, we may encounter a situation where the current project depends on a certain version, but another project depends on another version, which will cause dependency Conflict, and virtualenv solves this situation. Virtualenv creates a virtualized python runtime environment and installs the dependencies we need without interfering with each other between different projects. In short, that is, different virtual environments can be created on the same computer for different systems to use, and the operating environments between projects remain independent and are not affected by each other.

Before installing virtualenv, we need to install at least one version of python; because virtualenv is a third-party module of python, it must be installed based on the python environment;

 

First check if virtualenv is installed on your machine. Type in cmd

virtualenv --version

The appearance of the version number means that the installation is successful, otherwise it means that it is not installed.

 

☆ Install vitualenv

If you want to use the python virtual environment for development, you first need to install virtualenv.

Use the command in cmd:

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple/ virtualenv

Among them, -i https://pypi.tuna.tsinghua.edu.cn/simple/ is optional and used to specify the mirror address.

The pip here is the pip associated with which python version is used (if the system has multiple python versions), it depends on your system environment variable configuration

See the picture below:

[The following warning (WARNING), to the effect:

Warning: The script virtualenv.exe is installed in "D:\pyenv\.pyenv\pyenv-win\versions\3.8.1\Scripts" but not on the path.

Consider adding this directory to the path, or if you want to suppress this warning, use --no warn script location.

Successfully installed appdirs-1.4.4 distlib-0.3.1 filelock-3.0.12 six-1.15.0 virtualenv-20.4.3

Warning: You are using pip version 19.2.3, but version 21.0.1 is available.

You should consider upgrading via the'python-m pip install--upgrade pip' command.

 

Reminder, you need to pay attention to the path where the warning virtualenv.exe is located. Mine is D:\pyenv\.pyenv\pyenv-win\versions\3.8.1\Scripts

Please add it to the path in the system environment variables

 

☆View version

virtualenv --version

 

☆Use help

virtualenv -h

 

【☆Uninstall virtualenv

pip uninstall virtualenv 】

 

☆Establish a virtual environment

virtualenv <virtual environment name> 

Generate a corresponding folder in the current directory-you can create a directory, switch to the past-used to manage all virtual environments.

You can use the option -p to specify a version of the python environment, which will be used when multiple python versions are installed in your system, such as: -pd:\pyenv\.pyenv\pyenv-win\versions\3.8.1\python. exe; by default, virtualenv will give priority to its host python environment, that is, it will select which version as the default python isolation environment by default under which python version it is installed in.

Now create a virtual environment named myvenv in the current directory C:\Users\Wang:

virtualenv myvenv

According to the prompt, open the folder where the virtual environment is located as shown in the figure below:

Please pay attention to the activate.bat and Deactivate.bat files and their locations in the above figure, which will be used below.

☆ Activate the virtual environment

myvenv\Scripts\activate

 

☆ View the installed packages in the current virtual environment

pip list

 

You can use pip to install some plug-ins in this project, you can use pip to install some plug-ins in this project, that is, after entering the virtual environment, you can install various framework dependency packages through the pip install <packages name> command, not to mention here Up.

 

☆ Exit the virtual environment

myvenv\Scripts\Deactivate

 

 

 

Guess you like

Origin blog.csdn.net/cnds123/article/details/115185918
Recommended