開發環境
pyenv
- 使用github倉庫代碼安裝pyenv
mkdir ~/.pyenv
git clone https://github.com/pyenv/pyenv.git ~/.pyenv
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile
echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi' >> ~/.bash_profile
source ~/.bash_profile
Fish shell note: 添加到 ~/.config/fish/config.fish
status --is-interactive; and source (pyenv init -|psub)
- 使用離線包安裝python
NOTE:國內下載很慢,建議使用 搜狐鏡像 下載到本地進行安裝
mkdir ~/.pyenv/cache
wget http://mirrors.sohu.com/python/$version/Python-$version.tar.xz -P ~/.pyenv/cache
- 安裝你需要的 Python 版本
pyenv install $version
4.切換 Python 版本
pyenv local $version
pyenv-virtualenv
- 安裝
git clone https://github.com/pyenv/pyenv-virtualenv.git $(pyenv root)/plugins/pyenv-virtualenv
echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bash_profile
source ~/.bash_profile
Fish shell note: 添加到 ~/.config/fish/config.fish
status --is-interactive; and source (pyenv virtualenv-init -|psub)
- 切換 virtualenv
pyenv virtualenv 3.6.3 venv36
pyenv virtualenvs
3.6.3/envs/venv36 (created from /home/username/.pyenv/versions/3.6.3)
* venv36 (created from /home/username/.pyenv/versions/3.6.3)
3.激活 virtualenv
pyenv activate <name>
pyenv deactivate
- 刪除指定 virtualenv
pyenv uninstall <name>