系统相关
首页 > 系统相关> > 在Ubuntu中安装Python虚拟环及virtualenvwrapper

在Ubuntu中安装Python虚拟环及virtualenvwrapper

作者:互联网

一、安装pip包管理器

python@python:~$ sudo apt install python3-pip

在这里插入图片描述
二、安装virtualenv及virtualenvwrapper

sudo pip3 install virtualenv
sudo pip3 install virtualenvwrapper
sudo apt install virtualenv

在这里插入图片描述
在这里插入图片描述
三、配置~/.bashrc

source ~/.bashrc

在最后添加如下内容:

export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
export VIRTUALENVWRAPPER_VIRTUALENV=/usr/bin/virtualenv
source /usr/local/bin/virtualenvwrapper.sh

使配置生效

python@python:~$ source ~/.bashrc 
virtualenvwrapper.user_scripts creating /home/python/HOME/.virtualenvs/premkproject
virtualenvwrapper.user_scripts creating /home/python/HOME/.virtualenvs/postmkproject
virtualenvwrapper.user_scripts creating /home/python/HOME/.virtualenvs/initialize
virtualenvwrapper.user_scripts creating /home/python/HOME/.virtualenvs/premkvirtualenv
virtualenvwrapper.user_scripts creating /home/python/HOME/.virtualenvs/postmkvirtualenv
virtualenvwrapper.user_scripts creating /home/python/HOME/.virtualenvs/prermvirtualenv
virtualenvwrapper.user_scripts creating /home/python/HOME/.virtualenvs/postrmvirtualenv
virtualenvwrapper.user_scripts creating /home/python/HOME/.virtualenvs/predeactivate
virtualenvwrapper.user_scripts creating /home/python/HOME/.virtualenvs/postdeactivate
virtualenvwrapper.user_scripts creating /home/python/HOME/.virtualenvs/preactivate
virtualenvwrapper.user_scripts creating /home/python/HOME/.virtualenvs/postactivate
virtualenvwrapper.user_scripts creating /home/python/HOME/.virtualenvs/get_env_details

四、创建虚拟环境

mkvirtualenv py_django --python=/usr/bin/python3
#指定Python版本为python3虚拟环境名为:py_django

在这里插入图片描述
五、激活虚拟环境

workon py_django

在这里插入图片描述
六、退出及删除虚拟环境

#退出
deactivate
#删除
rmvirtualenv

标签:环及,virtualenvs,Python,python,virtualenvwrapper,user,HOME,creating
来源: https://blog.csdn.net/lb0737/article/details/89041453