这个工具用来方便地切换不同版本的python。
安装
curl -L https://raw.githubusercontent.com/pyenv/pyenv-installer/master/bin/pyenv-installer | bash
我使用的shell是fish,把它加入$PATH里面,因为经常需要把某个路径加入到$PATH里,所以以前写了一个函数,这样查看函数:
❯ functions add_to_path 2s 140ms
function add_to_path --description 'Persistently prepends paths to your PATH'
set --universal fish_user_paths $fish_user_paths $argv
end
新建函数:
❯ function add_to_path --description 'Persistently prepends paths to your PATH' 396ms
set --universal fish_user_paths $fish_user_paths $argv
end
保存函数:
❯ funcsave add_to_path
把pyenv
加入到$PATH里面:
❯ add_to_path ~/.pyenv/bin/
更新
pyenv update
帮助
❯ pyenv --help 183ms
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
另外,列出可安装的python版本:
❯ pyenv install --list
安装某个版本:
❯ pyenv install 2.7.13 137ms
Downloading Python-2.7.13.tar.xz...
-> https://www.python.org/ftp/python/2.7.13/Python-2.7.13.tar.xz
Installing Python-2.7.13...
Installed Python-2.7.13 to /home/repl/.pyenv/versions/2.7.13
效果
然而我发现并没有用。无意中安装了一个fisherman
的插件:
fisher pyenv
fisherman
是fish
的一个插件管理器,如果需要没有安装fisherman
:
curl -Lo ~/.config/fish/functions/fisher.fish --create-dirs git.io/fisher
这样就好了:
❯ pyenv versions 05:59
system
2.7.13
3.5.2
* 3.6.1 (set by /home/repl/.pyenv/version)
repl at Planet in ~
❯ python --version; and pip --version 164ms
Python 3.6.1
pip 9.0.1 from /home/repl/.pyenv/versions/3.6.1/lib/python3.6/site-packages (python 3.6)
repl at Planet in ~
❯ pyenv global 2.7.13; and python --version; and pip --version 919ms
Python 2.7.13
pip 9.0.1 from /home/repl/.pyenv/versions/2.7.13/lib/python2.7/site-packages (python 2.7)