<meta charset="utf-8">
先安装git:
$ yum install git
了解官方手册,请移步:https://github.com/pyenv/pyenv
首先安装依赖包
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
安装pyenv 先看下面,根据系统输入命令
$ git clone https://github.com/pyenv/pyenv.git ~/.pyenv
$ echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile
$ echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >>~/.bash_profile
$ echo 'eval "$(pyenv init -)"' >>~/.bash_profile
$ exec $SHELL -l
#即是启动语句,重启系统执行这条语句
使用 pyenv 安装 python 时,默认从 python.org
下载指定版本,往往特别慢,经常下载失败,这时可以先从官网下载所需要的版本的源代码到 ~/.pyenv/cache
目录下,再执行安装命令(亲测很好用)。
注意这里要下载的是类似于 Python-3.7.3.tar.xz
这样的压缩文件,要到官网 sourcecode 页面 才可以下载。
加速
下载需要的版本放到~/.pyenv/cache文件夹下面
然后执行 pyenv install 版本号 安装对应的python版本
傻瓜式脚本如下,其中v表示要下载的版本号
v=3.7.3;wget https://npm.taobao.org/mirrors/python/\$v/Python-\$v.tar.xz -P ~/.pyenv/cache/;pyenv install $v
http://mirrors.sohu.com/python/ 搜狐镜像
https://npm.taobao.org/mirrors/python/ 淘宝镜像
基本命令
pyenv commands
查看pyenv命令
pyenv install --list
查看可安装的python版本
pyenv versions
查看已安装版本
pyenv version
查看当前使用的python版本
pyenv install -v
版本号 安装python
pyenv rehash
刷新python已安装列表
pyenv uninstall
版本号 删除python
pyenv global
版本号 设置当前全局python版本
pyenv local
版本号 设置局部python版本
pyenv local --unset
取消局部python版本设置,或者删除当前目录下的.python-version文件
pyenv help
witcomm@storage90:~$ pyenv help
Usage: pyenv <command> [<args>]
Some useful pyenv commands are:
commands List all available pyenv commands
commands List all available pyenv commands
exec Run an executable with the selected Python version
global Set or show the global Python version
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
local Set or show the local application-specific Python version
prefix Display prefix for a Python version
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 a specific Python version
version Show the current Python version 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
网友评论