posts - 225, comments - 62, trackbacks - 0, articles - 0
   :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

Python虚拟环境virtualenv

Posted on 2019-11-17 14:07 魔のkyo 阅读(218) 评论(0)  编辑 收藏 引用 所属分类: Python
安装
pip3 install virtualenv
pip3 install virtualenvwrapper

修改用户家目录下的配置文件.bashrc,添加如下内容:
export WORKON_HOME=$HOME/.virtualenvs export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3 source /usr/local/bin/virtualenvwrapper.sh

执行.bashrc,让修改立即生效
source ~/.bashrc

创建虚拟环境
mkvirtualenv <环境名>

进入虚拟环境
workon <环境名>

从虚拟环境中退出
deactivate

删除虚拟环境
rmvirtualenv <环境名>

导出当前环境已安装的包
pip freeze > requirements.txt

安装包列表
pip install [-i https://指定安装源] -r requirements.txt

国内可选安装源地址:

永久更换安装源
编辑 ~/.pip/pip.conf

## Note, this file is written by cloud-init on first boot of an instance
#
# modifications made here will not survive a re-bundle.
#
##
[global]
index
-url=http://mirrors.cloud.aliyuncs.com/pypi/simple/

[install]
trusted
-host=mirrors.cloud.aliyuncs.com
只有注册用户登录后才能发表评论。