如何在 Mac OS 上安装 2 个 Anacondas(Python 2 和 3)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24405561/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 04:33:40  来源:igfitidea点击:

How to install 2 Anacondas (Python 2 and 3) on Mac OS

pythonmacosanaconda

提问by night_bat

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?

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

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-learnfor Python 3 environment and something like conda2 install scikit-learnfor Python 2.

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

采纳答案by asmeurer

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

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

conda create -n python2 python=2.7 anaconda

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

这将创建一个名为的环境python2,其中包含 Anaconda 的 Python 2.7 版本。您可以使用以下命令激活此环境

source activate python2

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

这会将环境(通常~/anaconda/envs/python2)放在您的 前面PATH,这样当您python在终端上键入时,它将从该环境加载 Python。

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

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

回答by Axis

Edit!: Please be sure that you should have both Python installed on your computer.

编辑!:请确保您的计算机上都安装了 Python。

Maybe my answer is late for you but I can help someone who has the same problem!

也许我的回答对你来说晚了,但我可以帮助有同样问题的人!

You don't have to download both Anaconda.

您不必同时下载两者Anaconda

If you are using Spyderand Jupyterin Anaconda environmen and,

如果您在 Anaconda 环境中使用SpyderJupyter,并且,

If you have already Anaconda 2 type in Terminal:

如果您已经在终端中输入了 Anaconda 2:

    python3 -m pip install ipykernel

    python3 -m ipykernel install --user

If you have already Anaconda 3 then type in terminal:

如果您已经安装了 Anaconda 3,请在终端中输入:

    python2 -m pip install ipykernel

    python2 -m ipykernel install --user

Then before use Spyderyou can choose Python environment like below! Sometimes only you can see root and your new Python environment, so root is your first anaconda environment!

然后在使用之前Spyder您可以选择如下Python环境!有时只有你才能看到 root 和你的新 Python 环境,所以 root 是你的第一个 anaconda 环境!

Anaconda spyder Python 2.7 or 3.5

蟒蛇 spyder Python 2.7 或 3.5

Also this is Jupyter. You can choose python version like this!

这也是 Jupyter。你可以选择这样的python版本!

Jupyter Notebook

Jupyter 笔记本

I hope it will help.

我希望它会有所帮助。

回答by David

This may be helpful if you have more than one python versions installed and dont know how to tell your ide's to use a specific version.

如果您安装了多个 python 版本并且不知道如何告诉您的 ide 使用特定版本,这可能会有所帮助。

  1. Install anaconda. Latest version can be found here
  2. Open the navigator by typing anaconda-navigatorin terminal
  3. Open environments. Click on createand then choose your python version in that.
  4. Now new environment will be created for your python version and you can install the IDE's(which are listed there) just by clicking installin that.
  5. Launch the IDE in your environment so that that IDE will use the specified version for that environment.
  1. 安装anaconda. 最新版本可以在这里找到
  2. 通过输入anaconda-navigator终端打开导航器
  3. 开放的环境。单击create,然后在其中选择您的 Python 版本。
  4. 现在将为您的 python 版本创建新环境,您只需单击即可安装 IDE(在此处列出)install
  5. 在您的环境中启动 IDE,以便该 IDE 将使用该环境的指定版本。

Hope it helps!!

希望能帮助到你!!