具有默认的Mac Python 2.7和Anaconda Python 3 [英] having default Mac Python 2.7 and Anaconda Python 3

查看:236
本文介绍了具有默认的Mac Python 2.7和Anaconda Python 3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想保留Mac Python作为我的主要"Python".原因是在Python网站此处中的推荐.我还想为我的Python3(Anaconda)添加一个单独的环境.

I want to keep the Mac Python as my main 'python'. The reason for that is the recommendation in Python website here. I also want to add a separate environment for my Python3 (Anaconda).

为此,我安装了Anaconda Python以访问Conda,然后使用以下命令为Python3创建了一个环境:

For doing that I installed the Anaconda Python to get access to Conda and then I made an environment for my Python3 using the following command:

conda create -n py36 python=3.6 anaconda

当我安装Anaconda python时,将其添加到我的.bash_profile文件中以访问所有conda命令:

When I installed the Anaconda python it added this to my .bash_profile file to get access to all conda commands:

# added by Anaconda3 4.4.0 installer
# export PATH="/Users/omidb/anaconda/bin:$PATH"

现在我的默认python是我不想使用的蟒蛇python.

Now my default python is anaconda python which I don't want to.

如何将默认的Mac python作为我的主要python,然后当我需要Anaconda时,只需使用source activate py36即可?

How can I have default Mac python as my main python and then when I needed Anaconda, just use source activate py36 ?

推荐答案

更新后的答案

经过测试后,我觉得应该提供此作为简单的解决方案,以使用Mac Python作为默认值,并且仅在需要时才使用Conda Python.

UPDATED ANSWER

After testing this, I feel it's appropriate to offer this as a simple solution for using Mac Python as the default and only using Conda Python when desired.

您需要通过export命令将conda路径添加/移动到PATH环境的末尾.这应该允许您将Mac Python用作默认值,并且仅在调用source activate py36之后使用Anaconda Python.

You need to add/move the conda path to the end of your PATH environment via export command. This should allow you to use the Mac Python as the default and only use Anaconda Python after calling source activate py36.

export PATH="$PATH:/Users/omidb/anaconda/bin"

路径分辨率

此解决方案假定PATH中已经有/usr/bin/(Mac Python在其中).解析顺序应首先检查该目录,前提是该目录位于PATH中.另外,此设置不需要/usr/local/bin中的符号链接.我不喜欢为可以使用用户资源(目录)完成的解决方案操纵系统级资源.

Path Resolution

This solution assumes you have /usr/bin/ (where Mac Python is) already in your PATH. Resolution order should check that directory first assuming it's first in the PATH. Also, this setup does not require symlinks in /usr/local/bin. I am not a fan of manipulating system-level resources for solutions that can be done with user resources (directories).

将Anaconda路径移动到PATH环境变量的末尾后,可以验证which python引用了/usr/bin/python(Mac Python的位置).默认情况下,您将在命令行上运行Mac python.

After moving the Anaconda path to the end of your PATH environment variable, you can validate that which python references /usr/bin/python, the location for Mac Python. You will run Mac python by default at the command line.

如前所述,要使用conda虚拟环境,必须调用source activate py36.无需向/usr/local/bin添加符号链接,因为它们已通过~/anaconda/bin/提供.

As previously noted, you have to call source activate py36 when you want to use the conda virtual environment. There is no need for adding symlinks to /usr/local/bin as they are already available through ~/anaconda/bin/.

此外,source activate py36(或任何其他Anaconda环境),它将为Anaconda python添加适当的环境路径到您的PATH环境变量的开头,该变量将被执行(请参阅路径分辨率")在命令行上以python运行时.您可以在运行source activate py36之后使用which python对此进行验证. conda还将先前的路径存储为环境变量CONDA_PATH_BACKUP.

Furthermore, source activate py36 (or any other Anaconda environment), it will add the appropriate environment path for Anaconda python to the beginning of your PATH environment variable, which (referring back to Path Resolution) would be executed when run as python on the command line. You can validate this with which python after running source activate py36. conda also stores the previous path as the environment variable CONDA_PATH_BACKUP.

运行source deactivate后,将还原原始路径,因此您将返回到运行Mac python.

After running source deactivate, the original path is restored, so you will then be back to running Mac python.

这篇关于具有默认的Mac Python 2.7和Anaconda Python 3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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