使用pyenv管理Python的运行环境


作者Lou Xiao创建时间2020-04-20 17:24:00更新时间2020-12-19 01:16:00

操作系统: CentOS 7.x

install requirement

1.双击鼠标左键复制此行;2.单击复制所有代码。
                                
                                    
1 # CentOS 7.x/Redhat 7/Fedora 21 and below
2 yum install gcc zlib-devel bzip2 bzip2-devel readline-devel sqlite sqlite-devel openssl-devel tk-devel libffi-devel ccache
3
4 # Ubuntu/Debian/Mint:
5 sudo apt-get update; sudo apt-get install --no-install-recommends make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev

download pyenv

1.双击鼠标左键复制此行;2.单击复制所有代码。
                                
                                    
1 git clone https://github.com/pyenv/pyenv.git ~/.pyenv
2 git clone https://github.com/pyenv/pyenv-virtualenv.git ~/.pyenv/plugins/pyenv-virtualenv
3 git clone https://github.com/yyuu/pyenv-ccache.git ~/.pyenv/plugins/pyenv-ccache
4 mkdir -p ~/.pyenv/cache

修改~/.bashrc

1.双击鼠标左键复制此行;2.单击复制所有代码。
                                
                                    
1 cat >> ~/.bashrc <<'EOF'
2 # pyenv
3 export PYENV_ROOT="$HOME/.pyenv"
4 export PATH="$PYENV_ROOT/bin:$PATH"
5 export PYTHON_BUILD_CACHE_PATH="$PYENV_ROOT/cache/"
6 if command -v pyenv &>/dev/null; then
7 eval "$(pyenv init -)"
8 eval "$(pyenv virtualenv-init -)"
9 fi
10 EOF

管理环境

1.双击鼠标左键复制此行;2.单击复制所有代码。
                                
                                    
1 # 列出所有版本
2 pyenv install --list
3
4 # 安装指定版本
5 pyenv install 3.6.10
6
7 # 下载指定版本
8 pyenv uninstall 3.6.10
9
10 # 临时激活某版本
11 pyenv shell 3.6.10
12
13 # 全局(永久\默认)激活某版本
14 pyenv global 3.6.10
15 #

全部命令

1.双击鼠标左键复制此行;2.单击复制所有代码。
                                
                                    
1 $ pyenv
2 pyenv 1.2.18-4-g5b009e8
3 Usage: pyenv <command> [<args>]
4
5 Some useful pyenv commands are:
6 activate Activate virtual environment
7 commands List all available pyenv commands
8 deactivate Deactivate virtual environment
9 exec Run an executable with the selected Python version
10 global Set or show the global Python version(s)
11 help Display help for a command
12 hooks List hook scripts for a given pyenv command
13 init Configure the shell environment for pyenv
14 install Install a Python version using python-build
15 local Set or show the local application-specific Python version(s)
16 prefix Display prefix for a Python version
17 rehash Rehash pyenv shims (run this after installing executables)
18 root Display the root directory where versions and shims are kept
19 shell Set or show the shell-specific Python version
20 shims List existing pyenv shims
21 uninstall Uninstall a specific Python version
22 version Show the current Python version(s) and its origin
23 --version Display the version of pyenv
24 version-file Detect the file that sets the current pyenv version
25 version-name Show the current Python version
26 version-origin Explain how the current Python version is set
27 versions List all Python versions available to pyenv
28 virtualenv Create a Python virtualenv using the pyenv-virtualenv plugin
29 virtualenv-delete Uninstall a specific Python virtualenv
30 virtualenv-init Configure the shell environment for pyenv-virtualenv
31 virtualenv-prefix Display real_prefix for a Python virtualenv version
32 virtualenvs List all Python virtualenvs found in `$PYENV_ROOT/versions/*'.
33 whence List all Python versions that contain the given executable
34 which Display the full path to an executable
35
36 See `pyenv help <command>' for information on a specific command.
37 For full documentation, see: https://github.com/pyenv/pyenv#readme
文章目录