python 俩个版本是不兼容的,在语法上有一点区别,但是对于我这种有轻度强迫症的人,一般软件或者程序版本都希望用最新的,但是python很多的扩展库都 不支持3版本,所以想办法装多个版本的python
安装配置Python版本管理器pyenv
1. 安装pyenv
brew install pyenv
安装的过程中发现没有安装brew
https://brew.sh/index_zh-cn.html
这个是官网,按照上面提示按照就可以
终端输入:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
我在安装过程中出现下载失败的情况,如果同样出现这样的情况的同学可以多试一次就可以。
3. 查看已经安装了哪些版本的Python
pyenv versions
其中版本号前面有*号的就是当前生效的版本,查看当前生效的版本也可以用pyenv version
4. 安装指定版本的Python
pyenv install 3.5.0
#安装完成后必须rehash
pyenv rehash
安装过程中,也是出现报错BUILD FAILED (OS X 10.10.5 using python-build 20160130),解决办法见pyenv BUILD FAILED解决方法
5. 切换和使用指定的版本Python版本有3种方法
➜ ~ pyenv
pyenv 20150310
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: https://github.com/yyuu/pyenv#readme
特别建议:
系统全局用系统默认的Python比较好,不建议直接对其操作
pyenv global system
用local进行指定版本切换,一般开发环境使用。
pyenv local 2.7.10
对当前用户的临时设定Python版本,退出后失效
pyenv shell 3.5.0
取消某版本切换
pyenv local 3.5.0 --unset
优先级关系:shell——local——global
#####另外最重要的一点,当执行了pyenv shell/local/global 命令后,一定要执行 source ~/.zshrc ,不然切换版本就不会生效。
可以参考:
https://www.cnhzz.com/pyenv_virtualenv_virtaulenvwrapper/