Ubuntu安装virtualenvwrapper

image.png

环境:Ubuntu 16.04.3 LTS

1. 安装virtualenv

pip3 install virtualenv
由于不确定之前是否安装过,查看一下

ubuntu@DESKTOP-AAH6KJH:~$ pip3 list
.........
virtualenv (15.0.1)
wheel (0.29.0)
........
You are using pip version 8.1.1, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

看到输出信息,它建议我升级pip3,那我就从善如流了

ubuntu@DESKTOP-AAH6KJH:~$ pip3 install --upgrade pip
Collecting pip
  Downloading pip-9.0.1-py2.py3-none-any.whl (1.3MB)
    100% |████████████████████████████████| 1.3MB 89kB/s
Installing collected packages: pip
Successfully installed pip-8.1.1
You are using pip version 8.1.1, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

查看升级后的版本

ubuntu@DESKTOP-AAH6KJH:~$ pip3 -V
pip 9.0.1 from /home/ubuntu/.local/lib/python3.5/site-packages (python 3.5)

2. 安装virtualenvwrapper

ubuntu@DESKTOP-AAH6KJH:~$ sudo pip3 install virtualenvwrapper
[sudo] ubuntu 的密码:
The directory '/home/ubuntu/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/ubuntu/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting virtualenvwrapper
  Downloading virtualenvwrapper-4.8.2-py2.py3-none-any.whl
Collecting virtualenv-clone (from virtualenvwrapper)
Collecting stevedore (from virtualenvwrapper)
  Downloading stevedore-1.28.0-py2.py3-none-any.whl
Requirement already satisfied: virtualenv in /usr/lib/python3/dist-packages (from virtualenvwrapper)
Requirement already satisfied: six>=1.10.0 in /usr/lib/python3/dist-packages (from stevedore->virtualenvwrapper)
Collecting pbr!=2.1.0,>=2.0.0 (from stevedore->virtualenvwrapper)
  Downloading pbr-3.1.1-py2.py3-none-any.whl (99kB)
    100% |████████████████████████████████| 102kB 45kB/s
Installing collected packages: virtualenv-clone, pbr, stevedore, virtualenvwrapper
Successfully installed pbr-3.1.1 stevedore-1.28.0 virtualenv-clone-0.2.6 virtualenvwrapper-4.8.2

其实到现在这一步还没有结束,因为还得需要创建虚拟环境的存放地址和设置环境变量

2.1创建虚拟环境目录

mkdir $HOME/.virtualenvs

2.2添加环境变量信息

在~/.bashrc中添加以下信息

# virtualenv-wrapper path
export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
export VIRTUALENVWRAPPER_VIRTUALENV=/usr/local/bin/virtualenv
source /usr/local/bin/virtualenvwrapper.sh
image.png

2.3重新加载环境变量

source ~/.bashrc

3.创建虚拟环境

mkvirtualenv -p python3 test

ubuntu@DESKTOP-AAH6KJH:~$ mkvirtualenv -p python3 test
Already using interpreter /usr/bin/python3
Using base prefix '/usr'
New python executable in /home/ubuntu/.virtualenvs/test/bin/python3
Also creating executable in /home/ubuntu/.virtualenvs/test/bin/python
Installing setuptools, pkg_resources, pip, wheel...done.
virtualenvwrapper.user_scripts creating /home/ubuntu/.virtualenvs/test/bin/predeactivate
virtualenvwrapper.user_scripts creating /home/ubuntu/.virtualenvs/test/bin/postdeactivate
virtualenvwrapper.user_scripts creating /home/ubuntu/.virtualenvs/test/bin/preactivate
virtualenvwrapper.user_scripts creating /home/ubuntu/.virtualenvs/test/bin/postactivate
virtualenvwrapper.user_scripts creating /home/ubuntu/.virtualenvs/test/bin/get_env_details
(test) ubuntu@DESKTOP-AAH6KJH:~$
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容