【Python 笔记】在Windows下使用virtualenv管理python虚拟环境

本文记录在Windows下使用virtualenv(v16.7.9)管理python虚拟环境的笔记.

1. virtualenv

GitHub
Documentation
PyPI

1.1 virtualenv 安装

>pip install virtualenv==16.7.9

16.7.9之后的版本有较大改动.

1.2 virtualenv 使用

创建虚拟坏境

>virtualenv --no-site-packages -p python venv

激活命令如下:

>\path\to\venv\Scripts\activate

退出虚拟环境

(venv)>deactivate

2. virtualenvwrapper

virtualenvwrapper-win PyPi
virtualenvwrapper-win GitHub

2.1 virtualenvwrapper 安装

>pip install virtualenvwrapper-win

2.2 virtualenvwrapper 使用

在系统变量里添加WORKON_HOME,自定义虚拟环境保存目录。如果不设置,默认为%USERPROFILE%\Envs.

在windows下可能存在一些bug:

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc1 in position 38: invalid start byte

修改...\Python36\Lib\site-packages\virtualenv.py第939行和941行:

# 939
line = line.decode(encoding,"ignore") # line = line.decode(encoding)
# 941
line = line.decode(fs_encoding,"ignore") # line = line.decode(fs_encoding)

创建虚拟环境:

>mkvirtualenv --no-site-packages -p python venv

打印虚拟环境列表:

>workon

Pass a name to activate one of the following virtualenvs:
==============================================================================
venv

激活虚拟环境:

>workon venv

退出虚拟环境:

>deactivate

猜你喜欢

转载自blog.csdn.net/RadiantJeral/article/details/110298069
今日推荐