$ pyenv versions * system (set by /Users/xxx/.pyenv/version) 3.7.0
查看可以安装的版本
1 2 3 4 5 6
$ pyenv install -l Available versions: 2.1.3 2.2.3 ... stackless-3.5.4
可以看到,可安装的版本有python2, python3, activepython, anaconda, ironpython, jython, pypy, stackless, etc.
安装指定版本
1 2 3 4 5 6
$ pyenv install 2.7.15 python-build: use openssl from homebrew python-build: use readline from homebrew Installing Python-2.7.15... python-build: use readline from homebrew Installed Python-2.7.15 to /Users/xxx/.pyenv/versions/2.7.15
注:Mac上安装可能会遇到The Python zlib extension was not compiled. Missing the zlib?的错误,可以尝试CFLAGS="-I$(xcrun --show-sdk-path)/usr/include" pyenv install 2.7.15
$ pyenv virtualenvs 3.7.0/envs/common3 (created from /Users/abc/.pyenv/versions/3.7.0) common3 (created from /Users/abc/.pyenv/versions/3.7.0)
创建virtualenv
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
$ pyenv virtualenv 2.7.15 my2.7.15 Collecting virtualenv Downloading https://files.pythonhosted.org/packages/8f/f1/c0b069ca6cb44f9681715232e6d3d65c75866dd231c5e4a88e80a46634bb/virtualenv-16.3.0-py2.py3-none-any.whl (2.0MB) 100% |████████████████████████████████| 2.0MB 117kB/s Requirement already satisfied: setuptools>=18.0.0 in ./.pyenv/versions/2.7.15/lib/python2.7/site-packages (from virtualenv) (39.0.1) Installing collected packages: virtualenv Successfully installed virtualenv-16.3.0 New python executable in /Users/abc/.pyenv/versions/2.7.15/envs/my2.7.15/bin/python2.7 Also creating executable in /Users/abc/.pyenv/versions/2.7.15/envs/my2.7.15/bin/python Installing setuptools, pip, wheel... done. Requirement already satisfied: setuptools in /Users/abc/.pyenv/versions/2.7.15/envs/my2.7.15/lib/python2.7/site-packages Requirement already satisfied: pip in /Users/abc/.pyenv/versions/2.7.15/envs/my2.7.15/lib/python2.7/site-packages
$ pyenv virtualenvs 2.7.15/envs/my2.7.15 (created from /Users/abc/.pyenv/versions/2.7.15) 3.7.0/envs/common3 (created from /Users/abc/.pyenv/versions/3.7.0) common3 (created from /Users/abc/.pyenv/versions/3.7.0) my2.7.15 (created from /Users/abc/.pyenv/versions/2.7.15)