Python's virtualenv

Source: Internet
Author: User

Virtualenv

The virtual Python Environment (venv) is a Python environment that helps you install different versions of Python modules on your local directory, so you can develop and test your code without having to install everything in your system.

Knowledge points
    • Installation of Virtualenv
    • Create a virtual environment
    • Activating a virtual environment
    • Using multiple Virtual Environments
    • Turn off the virtual environment
Experiment Step 1. Installation

Install PIP3 first.

$ sudo apt-get update$ sudo apt-get python3-pip

Install virtualenv with the following command:

$ sudo pip3 install virtualenv

2. Usage

We will create a virtual directory called, in which we will have two different virtual environments.

$ mkdir virtual

The following command creates an environment called VIRT1.

cd virtual$ virtualenv virt1

Now we activate this VIRT1 environment.

source virt1/bin/activate(virt1)[[email protected]]$

The first part of the prompt is the name of the current virtual environment, which helps you to identify which environment you are in when you have multiple environments.

Now we will install redis this Python module.

(virt1)$ sudo pip3 install redis

Use the deactivate command to close the virtual environment.

(virt1)$ deactivate$

Now we will create another virtual environment Virt2, we will install the module in the same redis , but the version is the old version of 2.8.

source virt2/bin/activate(virt2)$ sudo pip3 install redis==2.8

This can have many different environments for all your development needs.

Summarize

Always remember to create a virtual environment when developing new applications, which will help keep your system modules clean.

Python's virtualenv

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.