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
相关推荐
繁依Fanyi11 分钟前
使用 Spring Boot + Redis + Vue 实现动态路由加载页面
开发语言·vue.js·pytorch·spring boot·redis·python·算法
鸽芷咕28 分钟前
【Python报错已解决】xlrd.biffh.XLRDError: Excel xlsx file; not supported
开发语言·python·机器学习·bug·excel
Unicorn建模1 小时前
2024“华为杯”中国研究生数学建模竞赛(E题)深度剖析|数学建模完整过程+详细思路+代码全解析
python·算法·数学建模
神奇夜光杯1 小时前
Python酷库之旅-第三方库Pandas(123)
开发语言·人工智能·python·excel·pandas·标准库及第三方库·学习与成长
zhangbin_2371 小时前
【Python机器学习】NLP信息提取——提取人物/事物关系
开发语言·人工智能·python·机器学习·自然语言处理
_.Switch1 小时前
构建现代应用的Python Serverless架构详解
运维·开发语言·python·云原生·架构·serverless·restful
offduty1 小时前
Python基础03 | 变量和函数
python
空城皆是旧梦2 小时前
python爬虫初体验(二)
爬虫·python
crownyouyou2 小时前
第一次安装Pytorch
人工智能·pytorch·python
qq_435070782 小时前
python乱炖6——sum(),指定维度进行求和
pytorch·python·深度学习