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

查看:91
本文介绍了如何在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. Anaconda的软件包管理器Conda完全支持分离的环境.为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在该环境中安装软件包,方法是使用conda-n python2标志或激活该环境.

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