Python开发环境之pyenv环境搭建

本文介绍如何使用Pyenv在Linux环境下安装多个Python版本。包括下载Pyenv安装脚本、配置环境变量、安装指定版本的Python及其依赖项等步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

首先到Github上下载Pyenv相应的一键安装脚本,

$ curl -L /yyuu/pyenv-installer/master/bin/pyenv-installer | bash


安装完毕,设置环境变量,设置环境变量,可以添加到个人家目录的.bashrc或.bash_profile及系统的全
  局的/etc/profile,

# Load pyenv automatically by adding
# the following to ~/.bash_profile:

export PATH="/home/lavenliu/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"


设置完毕之后,可以在命令行进行验证,

[lavenliu@VM_113_230_centos ~]$ . ~/.bash_profile   
[lavenliu@VM_113_230_centos ~]$ pyenv 
pyenv 20160726
Usage: pyenv <command> [<args>]

Some useful pyenv commands are:
   commands    List all available pyenv commands
   local       Set or show the local application-specific Python version
   global      Set or show the global Python version
   shell       Set or show the shell-specific Python version
   install     Install a Python version using python-build
   uninstall   Uninstall a specific Python version
   rehash      Rehash pyenv shims (run this after installing executables)
   version     Show the current Python version and its origin
   versions    List all Python versions available to pyenv
   which       Display the full path to an executable
   whence      List all Python versions that contain the given executable

See `pyenv help <command>' for information on a specific command.
For full documentation, see: /yyuu/pyenv#readme


 以上都没有问题。比如,安装一个的版本Python,

pyenv install 

如果下载速度慢的话,可以事先下载之,放到~/.pyenv/cache目录即可。修改~/.pyenv/plugins/python-build/share/python-build/文件,

cat ~/.pyenv/plugins/python-build/share/python-build/
#require_gcc
install_package "openssl-" "/source/openssl-#b784b1b3907ce39abf4098702dade6365522a253ad1552e267a9a0e89594aa33" mac_openssl --if has_broken_mac_openssl
install_package "readline-" "/readline/readline-#56ba6071b9462f980c5a72ab0023893b65ba6debb4eeb475d7a563dc65cafd43" standard --if has_broken_mac_readline
if has_tar_xz_support; then
  install_package "Python-" "~/.pyenv/cache/Python-" ldflags_dirs standard verify_py35 ensurepip
else
  install_package "Python-" "~/.pyenv/cache/Python-" ldflags_dirs standard verify_py35 ensurepip
fi


由于没有~/.pyenv/cache目录,进行手工创建,

$ mkdir ~/.pyenv/cache


如果使用手工安装,则需要安装一些依赖,

# yum install -y gcc make patch gdbm-devel openssl-devel sqlite-devel zlib-devel bzip2-devel readline-devel


需要事先准备好Python-的安装包,放到~/.pyenv/cache目录下。然后,在命令行直接使用pyenv install 即可,

$ pyenv install 


安装完毕,使用version命令进行查看,

pyenv version
 (set by /home/lavenliu/.python-version)

至此,已经安装完毕。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值