欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 科技 > 能源 > CentOS配置python版本管理工具pyenv

CentOS配置python版本管理工具pyenv

2024/10/25 5:20:57 来源:https://blog.csdn.net/m0_70405779/article/details/142299147  浏览:    关键词: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

安装可能会比较慢,这边推荐一个快一点的方法

  1. 先在浏览器把python-3.7.7的包下载下来
    https://www.python.org/ftp/python/3.7.7/Python-3.7.7.tar.xz
  2. 然后把压缩包上传到 /root/.pyenv/cache/
    因为pyenv install 3.7.7会先查看cache中是否存在,有就直接安装,不用再去拉取
  3. 再次安装即可
    pyenv install 3.7.7
  4. 选择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 commandsexec        Run an executable with the selected Python versionglobal      Set or show the global Python version(s)help        Display help for a commandhooks       List hook scripts for a given pyenv commandinit        Configure the shell environment for pyenvinstall     Install a Python version using python-buildlatest      Print the latest installed or known version with the given prefixlocal       Set or show the local application-specific Python version(s)prefix      Display prefixes for Python versionsrehash      Rehash pyenv shims (run this after installing executables)root        Display the root directory where versions and shims are keptshell       Set or show the shell-specific Python versionshims       List existing pyenv shimsuninstall   Uninstall Python versionsversion     Show the current Python version(s) and its origin--version   Display the version of pyenvversion-file   Detect the file that sets the current pyenv versionversion-name   Show the current Python versionversion-origin   Explain how the current Python version is setversions    List all Python versions available to pyenvwhence      List all Python versions that contain the given executablewhich       Display the full path to an executableSee `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

在这里插入图片描述

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com