ubuntu下virtualenv與virtualenvwrapper的安裝與配置
文章目錄
對
pipenv
,pyenv
持觀望態度。暫時還是使用virtualenv
與virtualenvwrapper
進行項目開發
本機Python
版本是Python3.7
,ubuntu 19.10
檢查pip3
鏡像源
如果pip3
沒有設置國內鏡像源,需要先設置一下,下面設置的是清華源:
pip3 config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
安裝virtualenv
pip3 install virtualenv
安裝virtualenvwrapper
pip3 install virtualenvwrapper
如果virtualenvwrapper
一直卡着不動,可以先試試安裝一下pbr
pip3 install pbr
開始設置環境變量
sudo gedit /etc/profile
這樣就用gedit
打開了etc/profile
在末尾加上:
export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
這樣設置的意思是,將虛擬環境統一放置在$HOME/.virtualenvs
文件夾中
使之生效:
source /etc/profile
接下來繼續設置
bash版本
如果你用的是默認的bash shell,那麼打開~/.bashrc
sudo gedit ~/.bashrc
在文件末尾加入:
source ~/.local/bin/virtualenvwrapper.sh
使之生效:
source ~/.bashrc
zsh版本
如果你使用的是zsh,那麼打開~/.zshrc
sudo gedit ~/.zshrc
在文件末尾加入:
source ~/.local/bin/virtualenvwrapper.sh
使之生效:
source ~/.zshrc
驗證是否安裝成功:
先輸入virtualenv
,有輸出則成功
# mrcangye @ mrcangye in ~ [12:00:13]
$ virtualenv
usage: virtualenv [--version] [--with-traceback] [-v | -q] [--app-data APP_DATA] [--clear-app-data] [--discovery {builtin}] [-p py] [--creator {builtin,cpython3-posix,venv}] [--seeder {app-data,pip}] [--no-seed]
[--activators comma_sep_list] [--clear] [--system-site-packages] [--symlinks | --copies] [--download | --no-download] [--extra-search-dir d [d ...]] [--pip version] [--setuptools version] [--wheel version] [--no-pip]
[--no-setuptools] [--no-wheel] [--symlink-app-data] [--prompt prompt] [-h]
dest
virtualenv: error: the following arguments are required: dest
輸入mkvirtualenv
,有輸出則成功
# mrcangye @ mrcangye in ~ [12:00:16] C:2
$ mkvirtualenv
usage: virtualenv [--version] [--with-traceback] [-v | -q] [--app-data APP_DATA] [--clear-app-data] [--discovery {builtin}] [-p py] [--creator {builtin,cpython3-posix,venv}] [--seeder {app-data,pip}] [--no-seed]
[--activators comma_sep_list] [--clear] [--system-site-packages] [--symlinks | --copies] [--download | --no-download] [--extra-search-dir d [d ...]] [--pip version] [--setuptools version] [--wheel version] [--no-pip]
[--no-setuptools] [--no-wheel] [--symlink-app-data] [--prompt prompt] [-h]
dest
virtualenv: error: the following arguments are required: dest
輸入rmvirtualenv
,有輸出則成功
# mrcangye @ mrcangye in ~ [12:00:25] C:2
$ rmvirtualenv
Please specify an environment.