CentOS配置python版本管理工具pyenv
CentOS配置python版本管理工具pyenv
- 1.安装工具依赖
- 2.克隆python管理工具pyenv
- 3.配置环境变量
- 4.让环境生效
- 5.安装python指定版本
- 6.pyenv的简单使用
前言:每次配置Python环境都比较麻烦,遇到版本不兼容问题更复杂,且多次安装不同版本python版本也不好管理,所有我推荐使用Python的管理工具Pyenv,它可以方便地管理Python的不同版本。通过Pyenv,您可以轻松地切换和安装不同的Python版本。这样,您就可以避免版本兼容性的问题,并且更好地管理Python环境。
1.安装工具依赖
yum install -y git gcc zlib-devel bzip2 bzip2-devel readline-devel sqlite sqlite-devel openssl-devel xz xz-devel libffi-devel
2.克隆python管理工具pyenv
git clone https://github.com/pyenv/pyenv.git ~/.pyenv
3.配置环境变量
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(pyenv init -)"' >> ~/.bashrc
4.让环境生效
source ~/.bashrc
5.安装python指定版本
pyenv install 3.7.7
安装可能会比较慢,这边推荐一个快一点的方法
- 先在浏览器把python-3.7.7的包下载下来
https://www.python.org/ftp/python/3.7.7/Python-3.7.7.tar.xz
- 然后把压缩包上传到 /root/.pyenv/cache/
因为pyenv install 3.7.7会先查看cache中是否存在,有就直接安装,不用再去拉取- 再次安装即可
pyenv install 3.7.7
- 选择python3.7.7
pyenv global 3.7.7
6.pyenv的简单使用
[10:09:30 root@hadoop101 ~]#pyenv --help
Usage: pyenv <command> [<args>]
Some useful pyenv commands are:
commands List all available pyenv commands
exec Run an executable with the selected Python version
global Set or show the global Python version(s)
help Display help for a command
hooks List hook scripts for a given pyenv command
init Configure the shell environment for pyenv
install Install a Python version using python-build
latest Print the latest installed or known version with the given prefix
local Set or show the local application-specific Python version(s)
prefix Display prefixes for Python versions
rehash Rehash pyenv shims (run this after installing executables)
root Display the root directory where versions and shims are kept
shell Set or show the shell-specific Python version
shims List existing pyenv shims
uninstall Uninstall Python versions
version Show the current Python version(s) and its origin
--version Display the version of pyenv
version-file Detect the file that sets the current pyenv version
version-name Show the current Python version
version-origin Explain how the current Python version is set
versions List all Python versions available to pyenv
whence List all Python versions that contain the given executable
which Display the full path to an executable
See `pyenv help <command>' for information on a specific command.
For full documentation, see: https://github.com/pyenv/pyenv#readme
常用的如下:
# 查看已安装的所有python版本
pyenv versions
# 查看正在使用的python版本
pyenv version
# 下载指定python版本
pyenv install 3.7.7
# 选择使用指定python版本
pyenv global 3.7.7