Python3 venv Creating a virtual environment

Source: Internet
Author: User
Tags virtual environment

Introduction

Versions above Python3.3 are natively supported in virtual environments via the Venv module and can be used in place of Python's previous virtualenv.

The Venv module provides the creation of a lightweight "virtual environment" that provides isolation support from the system Python. Each virtual environment has its own Python binaries (allowing for different versions of the Python authoring environment) and can have its own set of Python packages.

It is important to note that the environment created with the "venv" command in Python3.3 does not contain "Pip" and you need to install it manually. This flaw has been improved in Python3.4.

Create a virtual environment

To create a virtual environment in the current directory:

$ python-m venv.

The following are the detailed usage parameters for "venv":

usage:venv [-h] [--system-site-packages] [--symlinks] [--Clear] [--upgrade] [--without-Pip] Env_dir [Env_dir ...] Creates virtual Python environmentsinchOneorMore target directories.positional arguments:env_dir A directory to create the environmentinch. Optional arguments:-H,--help show this help message andExit--system-site-packages Give access to theGlobalsite-Packages dir to the virtual environment. --symlinks Try to use symlinks rather than copies, when Symlinks is notThe default forThe platform. --copies Try to use copies rather than symlinks, even when Symlinks is the Defaul T forThe platform. --clear Delete The Environment directoryifit already exists. If notSpecified andThe directory exists, an error israised. --Upgrade Upgrade the environment directory to use this version of Python, assuming Python has been upgradedinch-Place . --without-pip Skips installingorUpgrading PIPinchThe Virtual environment (PIP isbootstrapped by default)

Activating a virtual environment

Under the POSIX standard platform:

$ source <venv>/bin/activate

Under Windows cmd:

C:> <venv>/scripts/activate.bat

Under Windows PowerShell:

PS c:> <venv>/scripts/activate.ps1

Test your virtual Environment

When the virtual environment is activated, the name of the current virtual environment is prompted at the command line, indicating that the activation was successful.

To install NumPy in the current virtual environment:

$ pip Install NumPy

The currently installed NumPy package does not conflict with the system and is tested below:

$ python Import NumPy Print (NumPy)

If you output the NumPy package path, it means everything is fine.

Official documentation Reference

Https://docs.python.org/3/library/venv.html

Python3 venv Creating a virtual environment

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.