如何在 Mac OS 上安装 2 个 Anacondas(Python 2 和 3) [英] How to install 2 Anacondas (Python 2 and 3) on Mac OS

查看:20
本文介绍了如何在 Mac OS 上安装 2 个 Anacondas(Python 2 和 3)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 Mac OS 比较陌生.我刚刚用最新的 Python 3(为我自己)安装了 XCode(用于 C++ 编译器)和 Anaconda.现在我想知道如何使用 Python 2 正确安装第二个 Anaconda(用于工作)?

I'm relatively new in Mac OS. I've just installed XCode (for c++ compiler) and Anaconda with the latest Python 3 (for myself). Now I'm wondering how to install properly second Anaconda (for work) with Python 2?

我需要两个版本才能使用 iPython 和 Spyder IDE.理想的方法是拥有完全独立的 Python 环境.例如,我希望我可以为 Python 3 环境编写 conda install scikit-learn 之类的代码,为 Python 2 编写诸如 conda2 install scikit-learn 之类的东西.

I need both versions to work with iPython and Spyder IDE. Ideal way is to have totally separate Python environments. For example, I wish I could write like conda install scikit-learn for Python 3 environment and something like conda2 install scikit-learn for Python 2.

推荐答案

无需再次安装 Anaconda.Conda 是 Anaconda 的包管理器,完全支持分离的环境.为 Python 2.7 创建环境的最简单方法是执行

There is no need to install Anaconda again. Conda, the package manager for Anaconda, fully supports separated environments. The easiest way to create an environment for Python 2.7 is to do

conda create -n python2 python=2.7 anaconda

这将创建一个名为 python2 的环境,其中包含 Python 2.7 版本的 Anaconda.你可以用

This will create an environment named python2 that contains the Python 2.7 version of Anaconda. You can activate this environment with

source activate python2

这会将环境(通常是 ~/anaconda/envs/python2)放在 PATH 的前面,这样当你输入 python 在终端,它将从该环境加载 Python.

This will put that environment (typically ~/anaconda/envs/python2) in front in your PATH, so that when you type python at the terminal it will load the Python from that environment.

如果你不想要所有的 Anaconda,你可以用你想要的任何包替换上面命令中的 anaconda.您可以稍后使用 conda 在该环境中安装软件包,方法是使用 -n python2 标志到 conda,或激活环境.

If you don't want all of Anaconda, you can replace anaconda in the command above with whatever packages you want. You can use conda to install packages in that environment later, either by using the -n python2 flag to conda, or by activating the environment.

这篇关于如何在 Mac OS 上安装 2 个 Anacondas(Python 2 和 3)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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