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