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.安装工具依赖

bash 复制代码
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

bash 复制代码
git clone https://github.com/pyenv/pyenv.git ~/.pyenv

3.配置环境变量

bash 复制代码
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(pyenv init -)"' >> ~/.bashrc

4.让环境生效

bash 复制代码
source ~/.bashrc

5.安装python指定版本

bash 复制代码
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的简单使用

bash 复制代码
[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

常用的如下:

bash 复制代码
# 查看已安装的所有python版本
pyenv versions
# 查看正在使用的python版本
pyenv version
# 下载指定python版本
pyenv install 3.7.7
# 选择使用指定python版本
pyenv global 3.7.7
相关推荐
偶尔微微一笑6 分钟前
AI网络渗透kali应用(gptshell)
linux·人工智能·python·自然语言处理·编辑器
船长@Quant2 小时前
文档构建:Sphinx全面使用指南 — 基础篇
python·markdown·sphinx·文档构建
喵手2 小时前
从 Java 到 Kotlin:在现有项目中迁移的最佳实践!
java·python·kotlin
liuweidong08022 小时前
【Pandas】pandas DataFrame rsub
开发语言·python·pandas
CH3_CH2_CHO2 小时前
不吃【Numpy】版
开发语言·python·numpy
-曾牛3 小时前
企业级AI开发利器:Spring AI框架深度解析与实战
java·人工智能·python·spring·ai·rag·大模型应用
Light603 小时前
智启未来:深度解析Python Transformers库及其应用场景
开发语言·python·深度学习·自然语言处理·预训练模型·transformers库 |·|应用场景
坤岭3 小时前
Python基础
python
心随_风动3 小时前
RHEL与CentOS:从同源到分流的开源操作系统演进
linux·开源·centos
一个天蝎座 白勺 程序猿3 小时前
Python爬虫(5)静态页面抓取实战:requests库请求头配置与反反爬策略详解
开发语言·爬虫·python