MacOS, Anaconda, and Homebrew
How to make Anaconda and Homebrew play nicely together.
Anaconda is a popular python development environment across platforms. However, on MacOS, though Homebrew by default install python as python3
, it may still create issue sometimes. This blog will look at the official and unofficial way to minimize potential conflict between the two.
Install Anaconda
Anaconda can be installed by downloading the package directly from official site, or via Homebrew. They do result with a different installation path.
Official Download
Download link is on Anaconda homepage: https://www.anaconda.com/
Anaconda directory: ~/anaconda3/
Homebrew
To use homebrew
|
|
Anaconda directory: /opt/homebrew/anaconda3/
conda init
After installing Anaconda, you need to run following once, depends on how it is installed.
Direct install:
|
|
Via Homebrew:
|
|
The command will add following to the end of ~/.zshrc
:
|
|
The above is created by a homebrew installation. Direct install will see /opt/homebrew/
changed to your home directory.
Activate Anaconda On Demand
There are situation we want to minimize Anaconda conflict with Homebrew or other non-anaconda base python projects. There are two ways to do it.
Official Way
Prevent anaconda to automatically activate the base
project when a shell start, while command conda
still works.
|
|
Unofficial Way
However there are are cases we want to remove any doubt and don’t want anaconda script to run at all.
In ~/.zshrc
, wrap anaconda initialization code in a zsh function condaOn()
like following:
|
|
DO NOT add any indent to the conda initialization code. Just add condaOn() {
before it, and }
after it like above.
When you need to use Anaconda, just type condaOn
:
|
|
Then start using conda
commands.