How to install a Python virtual environment under Windows

Source: Internet
Author: User
Tags virtual environment virtualenv

1. Preface

Because of the numerous versions of Python, there are also Python2 and Python3 debates, so some packages or third-party libraries are prone to version incompatibility issues.
By virtualenv This tool, you can build a series of virtual Python environments, and then install the required packages (in conjunction with PIP) in each environment, which is isolated from each other. As a standalone environment, version issues are not easily available and are also easy to deploy.

2. Installing virtualenv

Install using the following command:

pip install virtualenv

To test whether the installation was successful:

virtualenv --version
Basic use of 3.virtualenv
    • Create a virtual environment
      Command: VIRTUALENV Virtual environment name
virtualenv env
    • Create a virtual environment that specifies the version of the Python interpreter
      Command: Virtualenv-p Python interpreter path Virtual environment name
virtualenv -p c:\python27\python.exe env
    • Activating a virtual environment
activate venv
    • Stop a virtual environment
deactivate
    • Deleting a virtual environment
      To delete a virtual environment, simply delete its folder.
4. Installing Virtualenvwrapper

Virtualenvwrapper provides a series of commands that make working with virtual environments much more enjoyable. It puts all your virtual environments in one place.
Install under Windows platform using the following command (make sure virtualenv is installed):

pip install virtualenvwrapper-win
5. Set the environment variable Workon_home

Workon_home is a virtual environment created by Virtualenvwrapper-win stored in the path, in Windows, workon_home the default path is C:\Users\username\envs, If we want to customize the path of the store, you can set it by setting the environment variable workon_home.
By computer--Properties--Advanced system settings--environment variables--NEW "variable name" in System variables: workon_home, Variable value: "Your custom Path".

Basic use of 6.virtualenvwrapper
    • Create a virtual environment
      Command: MKVIRTUALENV Virtual environment name
mkvirtualenv env
    • Create a virtual environment that specifies the version of the Python interpreter
      Command: Mkvirtualenv-p Python interpreter path Virtual environment name
mkvirtualenv -p c:\python27\python.exe env

Once created, the environment is automatically activated, taking note of changes to the shell prompt:

(venv)c:\>
    • List all virtual environments that exist under the Workon_home path
lsvirtualenv
    • Activating the virtual environment you need to use
workon env
    • Enter the directory of the currently active virtual environment
cdvirtualenv
    • Enter the Site-packages directory for the currently active virtual environment
cdsitepackages
    • List all packages for the Site-packages directory of the currently active virtual environment
lssitepackages
    • Stop a virtual environment
deactivate
    • Deleting a virtual environment
rmvirtualenv env

How to install a Python virtual environment under Windows

Related Article

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.