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

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

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

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

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?

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.


回答 0

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

conda create -n python2 python=2.7 anaconda

这将创建一个名为python2Python Anaconda的环境。您可以使用

source activate python2

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

如果您不希望使用Anaconda的全部功能,则可以anaconda在上面的命令中将其替换为所需的任何软件包。您可以conda稍后使用-n python2标记conda或激活环境,以在该环境中安装软件包。

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

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

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.

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.


回答 1

编辑!:请确保您在计算机上同时安装了两个Python。

也许我的答案对您来说太迟了,但我可以帮助遇到同样问题的人!

您不必同时下载两者Anaconda

如果你正在使用SpyderJupyterAnaconda的环境下和,

如果您已经有Anaconda 2输入终端:

    python3 -m pip install ipykernel

    python3 -m ipykernel install --user

如果您已经有Anaconda 3,则输入终端:

    python2 -m pip install ipykernel

    python2 -m ipykernel install --user

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

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

希望对您有所帮助。

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

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.

If you are using Spyder and Jupyter in Anaconda environmen and,

If you have already Anaconda 2 type in Terminal:

    python3 -m pip install ipykernel

    python3 -m ipykernel install --user

If you have already Anaconda 3 then type in terminal:

    python2 -m pip install ipykernel

    python2 -m ipykernel install --user

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

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

I hope it will help.


回答 2

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

  1. 安装anaconda。最新版本可以在这里找到
  2. 通过输入anaconda-navigator终端打开导航器
  3. 开放环境。点击create,然后在其中选择您的python版本。
  4. 现在将为您的python版本创建新的环境,您只需单击即可安装IDE(在此处列出)install
  5. 在您的环境中启动IDE,以便该IDE将在该环境中使用指定的版本。

希望能帮助到你!!

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.

  1. Install anaconda. Latest version can be found here
  2. Open the navigator by typing anaconda-navigator in terminal
  3. Open environments. Click on create and 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 install in that.
  5. Launch the IDE in your environment so that that IDE will use the specified version for that environment.

Hope it helps!!