Python2与Python3创建虚拟环境
1. Python2创建虚拟环境
1-1. 安装虚拟环境模块
C:\envs>pip install virtualenvwrapper
1-2. 创建虚拟环境
C:\envs>python # 查看python版本
# Python 2.6.6 (r266:84297, Aug 24 2010, 18:46:32) [MSC v.1500 32 bit (Intel)] on win32
# Type "help", "copyright", "credits" or "license" for more information.
# >>>
C:\envs>python -m virtualenv py_ven26 # 创建虚拟机
# New python executable in py_ven26\Scripts\python.exe
# Installing setuptools................done.
# Installing pip...................done.
# windows中需要配置‘高级环境变量’
# 变量名:WORKON_HOME
# 变量值:C:\envs (虚拟环境存放的目录路径)
C:\envs>workon # 查看所有的虚拟环境
# Pass a name to activate one of the following virtualenvs:
# ==============================================================================
# py_ven26 # 虚拟环境
# tg26env # 虚拟环境
C:\envs>workon py_ven26 # 切换虚拟环境
(py_ven26) C:\envs>python # 虚拟环境中查看python版本
# Python 2.6.6 (r266:84297, Aug 24 2010, 18:46:32) [MSC v.1500 32 bit (Intel)] on win32
# Type "help", "copyright", "credits" or "license" for more information.
# >>> exit() # 退出python
2. Python3创建虚拟环境
2-1. 安装虚拟包
pip install virtualenv -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com
2-2. 创建虚拟环境
c:\envs>python
# Python 3.7.9 (tags/v3.7.9:13c94747c7, Aug 17 2020, 18:58:18) [MSC v.1900 64 bit (AMD64)] on win32
# Type "help", "copyright", "credits" or "license" for more information.
c:\envs>python -m virtualenv py379env
# created virtual environment CPython3.7.9.final.0-64 in 2075ms
# creator CPython3Windows(dest=C:\envs\py379env, clear=False, no_vcs_ignore=False, global=False)
# seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=C:\Users\Mace.Chen\AppData\Local\pypa\virtualenv)
# added seed packages: pip==22.3.1, setuptools==65.6.3, wheel==0.38.4
# activators BashActivator,BatchActivator,FishActivator,NushellActivator,PowerShellActivator,PythonActivator
# 激活虚拟环境
c:\envs>cd .\py379env\Scripts
c:\envs\py379env\Scripts>activate
# 成功激活虚拟环境
(py379env) c:\envs\py379env\Scripts>
# 通过workon查看,可按照3进行操作
(py379env) c:\envs\py379env\Scripts>workon
# Pass a name to activate one of the following virtualenvs:
# ==============================================================================
# py379env
3. workon命令管理虚拟机
3-1. 安装扩展包
# windows操作系统 workon命令管理虚拟机
pip install virtualenvwrapper-win
3-2. 配置高级变量
变量值:就是存放Python虚拟环境的目录路径