在Mac OS X上的python 2.7和python 3.5之间切换 [英] Switch between python 2.7 and python 3.5 on Mac OS X

查看:64
本文介绍了在Mac OS X上的python 2.7和python 3.5之间切换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通常使用Python 2.7,但最近在Mac OS X上使用Miniconda安装了Python 3.5.为这两个版本的python安装了不同的库.现在,在终端中输入关键字"python"或"python3"会调用python 3.5,而"python2"将返回"-bash:python2:not found".现在如何分别使用别名"python2"和"python3"专门调用它们?

I generally use Python 2.7 but recently installed Python 3.5 using Miniconda on Mac OS X. Different libraries have been installed for these two versions of python. Now, the entering either of the keywords 'python' or 'python3' in terminal invokes python 3.5, and 'python2' returns '-bash: python2: command not found'. How can I now invoke them specifically using aliases 'python2' and 'python3' respectively?

我当前正在使用OS X El Capitan.

I am currently using OS X El Capitan.

推荐答案

恕我直言,在macOS上使用两个不同的Python版本的最佳方法是通过homebrew.在macOS上安装自制软件之后,在终端上运行以下命令.

IMHO, the best way to use two different Python versions on macOS is via homebrew. After installing homebrew on macOS, run the commands below on your terminal.

brew install python@2
brew install python

现在,您可以通过调用python2来运行Python 2.7,或者可以通过调用python3来运行Python 3.除此之外,您还可以使用 virtualenv

Now you can run Python 2.7 by invoking python2 or Python 3 by invoking python3. In addition to this, you can use virtualenv or pyenv to manage different versions of python environments.

我从没有亲自使用 miniconda ,但从未使用过

I have never personally used miniconda but from the documentation, it looks like it is similar to using pip and virtualenv in combination.

这篇关于在Mac OS X上的python 2.7和python 3.5之间切换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆