进入github官方地址下载pyenv
与pyenv-virtualenv
代码
$ 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
Zsh note: Modify your ~/.zshenv
file instead of ~/.bash_profile
.
Add pyenv init
to your shell to enable shims and autocompletion. Please make sure eval "$(pyenv init -)"
is placed toward the end of the shell configuration file since it manipulates PATH
during the initialization.
$ echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi' >> ~/.bash_profile
Zsh note: Modify your ~/.zshenv
file instead of ~/.bash_profile
.
Restart your shell so the path changes take effect. You can now begin using pyenv.
exec "$SHELL"
Install Python versions into $(pyenv root)/versions
. For example, to download and install Python 3.7.3, run:
$ pyenv install 3.7.3
NOTE: If you need to pass configure option to build, please use CONFIGURE_OPTS
environment variable.
NOTE: If you want to use proxy to download, please use http_proxy
and https_proxy
environment variable.
NOTE: If you are having trouble installing a python version, please visit the wiki page about Common Build Problems
# 查看相应python环境
$ pyenv versions
# 创建某个项目所需的python环境
$ pyenv virtualenv 3.7.5 guanshu
# 激活项目所需的环境
$ pyenv activate guanshu
# 退出项目所在的环境
$ pyenv deactivate guanshu
原文:https://www.cnblogs.com/liuhuan086/p/12524854.html