安装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.
安装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
其实到现在这一步还没有结束,因为还得需要创建虚拟环境的存放地址和设置环境变量
创建虚拟环境目录
mkdir $HOME/.virtualenvs
添加环境变量信息
在~/.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
重新加载环境变量
source ~/.bashrc
创建虚拟环境
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:~$
使用
查看虚拟环境
workon 再两次tab键 或者 lsvirtualenv
创建虚拟环境
mkvirtualenv -p /usr/bin/python3 虚拟环境名
删除虚拟环境
rmvirtualenv cgWork
进入(切换)虚拟环境
workon 环境名
退出虚拟环境
deactivate
安装flask
pip install flask=1.0