Python虚拟环境管理

1、安装软件

1.1、安装virtualenv、virtualenvwrapper

pip3 install virtualenv
pip3 install --no-deps stevedore virtualenvwrapper

2、配置环境变量

mkdir /data//venv
echo 'export WORKON_HOME=/data/venv' >> .bashrc
echo 'export VIRTUALENVWRAPPER_PYTHON=/usr/local/python3/bin/python3' >> .bashrc
echo 'export VIRTUALENVWRAPPER_VIRTUALENV=/usr/local/python3/bin/virtualenv' >> .bashrc
echo 'source /usr/local/python3/bin/virtualenvwrapper.sh' >> .bashrc
source .bashrc

注意:virtualenv 和 virtualenvwrapper.sh 的路径位置

3、虚拟环境

3.1、创建虚拟环境

# 创建test虚拟环境
mkvirtualenv test

# 环境的目录位置:/data/venv/test/

注意:首次创建会自动进入虚拟环境的

3.2、退出虚拟环境

# 方法1
deactivate

# 方法2
exit

3.3、进入虚拟环境

3.3.1、查询存在的虚拟环境

register ~]# workon 
flask_env
test

3.3.2、进入虚拟环境

register ~]# workon test
(test) [root@register ~]# 

3.4、删除虚拟环境

rmvirtualenv test

# test 是虚拟环境的名字

 

posted @ 2023-04-11 12:03  小粉优化大师  阅读(55)  评论(0编辑  收藏  举报