当前位置: 首页 > article >正文

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 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

在这里插入图片描述


http://www.kler.cn/news/307586.html

相关文章:

  • Maven 常见问题以及常用命令
  • 函数题 6-2 多项式求值【PAT】
  • UVA-225 黄金图形 题解答案代码 算法竞赛入门经典第二版
  • 电脑浏览器访问华为路由器报错,无法访问路由器web界面:ERR_SSL_VERSION_OR_CIPHER_MISMATCH 最简单的解决办法!
  • 代码随想录打卡Day32
  • Unity 使用Spine动画切换时有残影
  • VSCode创建C++项目和编译多文件
  • java发邮件内容含表格实现方法?如何配置?
  • sqlgun新闻管理系统
  • 本地部署大语言模型详细操作步骤
  • Y电容(安规电容)的作用是什么?
  • 【C++】queue和priority_queue
  • Linux:进程(一)
  • 无人机建模详解!!!
  • [Leetcode LCR 154][Medium]-复杂链表的复制-链表
  • JSON数组
  • 通信工程学习:什么是接入网(AN)中的CF核心功能
  • dplyr、tidyverse和ggplot2初探
  • 一些学习three的小记录
  • RK3588九鼎创展方案在Arm集群服务器的项目中的应用分析​​
  • 关于决策树集成的一份介绍
  • IDEA 新版本设置菜单展开
  • Python 单元测试详解:Unittest 框架的应用与最佳实践
  • java.人机猜拳游戏
  • JVM 性能优化与调优-Shenandoah GC
  • [K8S]Forbidden: pod updates may not change fields other than
  • 【Linux】NAT
  • 医学数据分析实训 项目三 关联规则分析预备项目---购物车分析
  • Django——多apps目录情况下的app注册
  • 在Ubuntu 16.04上安装R的方法