Skip to content

Instantly share code, notes, and snippets.

@sp3c73r2038
Created August 7, 2013 03:12
Show Gist options
  • Save sp3c73r2038/6170869 to your computer and use it in GitHub Desktop.
Save sp3c73r2038/6170869 to your computer and use it in GitHub Desktop.
use pyenv then!

Use PyEnv Then!

Pythonbrew is now deprecated. So we should use pyenv then.

pyenv is inspired by rbenv and ruby-build, and is pretty handy.

install

cd ~
git clone https://github.com/yyuu/pyenv .pyenv
echo 'export PATH="$HOME/.pyenv/bin:$PATH"' >> ~/.bash_profile
$ echo 'eval "$(pyenv init -)"' >> ~/.bash_profile

reload your shell, and all set.

usage

install a python version

pyenv install 2.7.5
pyenv install 3.2.5

use python for current shell

pyenv shell 2.7.5

reset to system's python

pyenv shell system

use python for current project (a.k.a. current directory)

pyenv local 2.7.5

it writes a file named .python-version with content 2.7.5.

use python globally

pyenv global 2.7.5

it writes a file named ~/.pyenv/version with content 2.7.5.

use cache for source tarball

mkdir -p "$(pyenv root)/cache"

使用 pyenv 吧!

还记得以前发的Pythonbrew ( 以及Pythonbrew for anjuke ) 吗? 他已经 deprecated 了,并且推荐使用 pyenv 。

pyenv 他的灵感来自 rbenv 和 ruby-build , 非常顺手。

安装

从 github 拉取即可。

cd ~
git clone https://github.com/yyuu/pyenv .pyenv
echo 'export PATH="$HOME/.pyenv/bin:$PATH"' >> ~/.bash_profile
$ echo 'eval "$(pyenv init -)"' >> ~/.bash_profile

重载shell配置,OK 。

用法

安装特定版本的Python

pyenv install 2.7.5
pyenv install 3.2.5

切换当前shell使用的Python

pyenv shell 2.7.5

回到系统默认的Python

pyenv shell system

给当前项目 ( 即当前目录 ) 指定Python版本

pyenv local 2.7.5

这会在当前目录写入文件.python-version 内容为 2.7.5

全局切换Python脚本

pyenv global 2.7.5

这会在 ~/.pyenv/version 写入文件内容为 2.7.5

会源代码使用缓存 ( 不必每次安装都重新下载源代码包 )

mkdir -p "$(pyenv root)/cache"

目前还不适用于某些企业的生产环境 ( 限制不能访问公网 ),因为源代码包和 setuptools 以及 pip 都是从公网下载的。需要hack一下。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment