Many people use Python to develop projects that need to use Python2 or Python3. When it is not clear how to separate the environment, this is when the two environments start to fight, each silly can not tell. Virtual environment as a tool for isolation came into being, in fact, the biggest benefit of virtual environment is to isolate our development environment, so that each other is not affected. Today, xiaobian to give you a simple introduction to how to create a virtual environment under Windows, the specific tutorial is as follows.

1. The library required by the virtual environment is Virtualenv. Run PIP install virtualenv to install it, as shown in the following figure. The library already exists when you install it again.

2. After the installation is complete, you can directly create a virtual environment by running the virtualenv test command. Test is the name of the virtual environment and you can customize it. After a few moments, the virtual environment will be created automatically, as shown below.

3. By default, the environment will be created in the current directory, in this case C:Userslenovo. When you enter this directory, you can see that the test virtual environment has been created, as shown in the following figure.

4, of course, you can also view files through the command line window, as shown in the figure below.

5. Continue to open the Scripts folder to see Python files, as shown below.

6. Here we can see that there is an activate.bat file to activate the virtual environment. To activate the Python virtual environment, enter the activate.bat command directly from this directory, as shown below.

At this point, you can see that the test folder is at the front with extra parentheses, which indicates that we have successfully entered the virtual environment.

Enter Python in the virtual environment. You can see the python version, as shown below. This is Python3.

8. To exit Python, use the command exit() or the shortcut Ctrl+ Z, as shown below. To exit the Python virtual environment, type the command deactivate.bat in the current directory, as shown in the following figure.

The Python environment is set to Python3 by default. If you want to create a Python2 virtual environment, how do you do it? Stay tuned for the next article.

Life is short. I use Python