Python uses virtual environment, python Virtual Environment

Source: Internet
Author: User
Tags virtualenv

Python uses virtual environment, python Virtual Environment

 

Imagine the requirement. To write a series of 1.0 plug-ins used by a project, we need to use 2.0 for a new project. What should we do? Are all updated to version 2.0? In this way, the previous project cannot be maintained.

In this case, we need a virtual environment. Python supports such a plug-in, virtualenv

Install it as follows:

1. pip3 install virtualenv

2. cd A directory for storing virtual environments and creating Virtual Environments

Virtualenv -- no-site-packages venv is the name. You can name it by yourself. 3. activate the virtual environment source venv/bin/activate # source is the environment in linux. In windows, directly add cd to the scripts directory and execute activate.
The venv here is the name above. When this format is displayed, it indicates that it is in a virtual environment.
F: \ code library \ Virtual Environment virtualenv \ ven_test \ Scripts> activate (ven_test) F: \ code library \ Virtual Environment virtualenv \ ven_test \ Scripts>

 

There is no plug-in the environment, because when we create this virtual environment, we select no-site-packages.

Therefore, you need to reinstall all plug-ins.

4. Exit the Virtual Environment

Deactivate 

(Ven_test) F: \ code library \ Virtual Environment virtualenv \ ven_test \ Scripts> deactivateF: \ code library \ Virtual Environment virtualenv \ ven_test \ Scripts>

 

 

 

In fact, this function is also encapsulated for us in pycharm.

The following shows how to use the virtual environment in pycharm.

1. Create a virtual environment

 

Here you can choose whether to inherit the previous version of the plug-in

After confirmation, a virtual environment has been created and applied to our project.

 

In the project configuration, change the interpreter to the new virtual environment.

 

 

 

This is a new virtual environment. If you want to add an existing environment to pycharm, You need to select this

After that, find python.exe in the scriptsdirectory of the environment to be created, and add it.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.