Python3.3以上的版本通過venv模塊原生支持虛擬環境,可以代替Python之前的virtualenv。該venv模塊提供了創建輕量級“虛擬環境”,提供與系統Python的隔離支持。每一個虛擬環境都有其自己的Python二進制(允許有不同的Python版本創作環境),並且可以擁有自己獨立的一套Python包。Python3.3中使用”venv”命令創建的環境不包含”pip”,你需要進行手動安裝。在Python3.4中改進了這一個缺陷。
一、在當前目錄創建虛擬環境:
$ python -m venv .
二、”venv”的詳細使用參數:
usage: venv [-h] [--system-site-packages] [--symlinks] [--clear]
[--upgrade] [--without-pip] ENV_DIR [ENV_DIR ...]
Creates virtual Python environments in one or more target directories.
positional arguments:
ENV_DIR A directory to create the environment in.
optional arguments:
-h, --help show this help message and exit
--system-site-packages Give access to the global site-packages dir to the virtual environment.
--symlinks Try to use symlinks rather than copies, when symlinks are not the default for the platform.
--copies Try to use copies rather than symlinks, even when symlinks are the default for the platform.
--clear Delete the environment directory if it already exists. If not specified and the directory exists, an error is raised.
--upgrade Upgrade the environment directory to use this version of Python, assuming Python has been upgraded in-place.
--without-pip Skips installing or upgrading pip in the virtual environment (pip is bootstrapped by default)
三、激活虛擬環境
Posix標准平台下:$ source <venv>/bin/activate
Windows cmd : C:> <venv>/Scripts/activate.bat
Windows PowerShell: PS C:> <venv>/Scripts/Activate.ps1
Linux 平台:source activate
引用與 https://www.cnblogs.com/LittleMore/p/6693154.html