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

查看:38
本文介绍了在 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: command 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 或 <一个 href="https://github.com/pyenv/pyenv" rel="noreferrer">pyenv 来管理不同版本的 python 环境.

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 而是来自 文档, 看起来它类似于使用 pipvirtualenv 结合使用.

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天全站免登陆