Ubuntu安裝virtualenvwrapper

image.png

環(huán)境: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

其實到現(xiàn)在這一步還沒有結束,因為還得需要創(chuàng)建虛擬環(huán)境的存放地址和設置環(huán)境變量

2.1創(chuàng)建虛擬環(huán)境目錄

mkdir $HOME/.virtualenvs

2.2添加環(huán)境變量信息

在~/.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重新加載環(huán)境變量

source ~/.bashrc

3.創(chuàng)建虛擬環(huán)境

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:~$
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

友情鏈接更多精彩內容