mac python编译器 conda,具有默认的Mac Python 2.7和Anaconda Python 3

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).

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

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"

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

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

解决方案

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.

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 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).

Default Python Setup

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.

Running Conda Python

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/.

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.

Deactivating Conda

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值