5

It is well known that Anaconda installation on macOS can cause trouble with other widely used package/environment managers like Homebrew, Pyenv, Virtualenv, etc.

The majority of the solutions I've found are 'Anaconda-centric', i.e. using Anaconda as the main python manager and setup conda env for homebrew etc.

However, I am looking for a solution that's kind of 'Homebrew-centric', and setup Anaconda as a compliment. Anaconda should be set up in a way that when ever conda is used, it will work with its own Python, own packages. And leave the rest of system untouched.

The motivation for such solution is because that, for example, when one's main work-flow use homebrew Python3 (python3), homebrew pip (pip3) and Pyenv (pyenv) with requirement.txt. And occasionally using Anaconda when a project is required.

zrfrank
  • 2,631
  • 1
  • 12
  • 18
  • My answer does not fit with "It is well known.." in your question. Earlier Anaconda versions were installed in the current OSX user folder that the installation of Anaconda was done. In the last year or so I note Anaconda installation (at least Anacand3 on my Mac) now gets installed in the top level of the HD. Not in the individual user account folder system. An export path is added to the user folder in the current account. Hence when installing Anaconda3 5.2.0 late last year, in my main OSX user account, and using Terminal, the .bash_profile has added: `export PATH="/anaconda3/bin:$PATH"`. – Cam_Aust Feb 24 '19 at 11:47
  • I know the word "well-known" is probability too much, there're many blogs, GitHub issues and SO questions related to such problem though. Its often less a problem for researchers who use Anaconda heavily, but a hug problem for developer who relay more on other managers and use Anaconda occasionally. – zrfrank Feb 24 '19 at 12:16
  • The reason you describe above is exactly the problem. The 'anaconda-centric' solution use anaconda to manage everything python related. Some solution also use 'pyenv' to switch to homebrew python when use `brew` then switch back to anaconda managed environment. And the previous behavior you described is probably what I am looking for. So that Anaconda is set up in its own folder, and then anaconda python and pip is only activated when use `conda` command. Thus a total separation from the rest of the system. – zrfrank Feb 24 '19 at 12:22
  • Then I am hoping someone has a good neat well thought solution and answer. You have posted a good question in my view. – Cam_Aust Feb 24 '19 at 13:23
  • If you resolve an answer, do please post your own questions with your found solution. This is allowed. – Cam_Aust Feb 24 '19 at 21:23

1 Answers1

7

Rather than using Anaconda I would suggest using Miniconda, which includes only Python and conda (and a few support packages). Miniconda does not include all of the packages in Anaconda by default, but they can all be installed (with conda install anaconda). Once you download Miniconda, you can install it into your home folder at /Users/username/miniconda3. During the installation, you will be asked if you want to add some initialization code to your .bash_profile. Either choose yes or (if you chose no), then you can run

/Users/username/miniconda3/bin/conda init

to add the conda initialization to your .bash_profile. By default, this will activate the base environment, so you can change the default setting so the environment is not activated by default:

conda config --set auto_activate_base false

You'll probably need to open a new terminal so the conda command is available. Then, when you want to use a conda environment, you can conda activate that environment, but otherwise, conda's Python should not be on your PATH.

darthbith
  • 18,484
  • 9
  • 60
  • 76
  • Would this method resolve the conflict between brew python and anaconda python? The conflict as stated, ["Since python and anaconda conflict when executing activate command, I decided to use pyenv-virtualenv." ](https://www.soudegesu.com/en/python/pyenv/anaconda/) – zrfrank Feb 25 '19 at 03:57
  • What do you mean the conflict between them? As far as I'm aware, your shell will run the first executable named `python` (if you type `python`) that it can find on the `PATH`. Without out a conda environment activated, there should be no Anaconda Python's on the `PATH`. – darthbith Feb 25 '19 at 12:48
  • zrfrank, knowing that you appear new to SO, you might want to consider accepting the answer by darthbith if you find it is a satisfactory and confirmed workable solution. – Cam_Aust Feb 25 '19 at 14:37
  • @Cam_Aust I'm happy to make sure this is a complete answer, I'm just not sure what zrfrank is asking, exactly :-) – darthbith Feb 25 '19 at 14:42
  • Alternatively, the lazy solution is to add a line in the `bash_profile` or `.zshrc` below the anaconda generated initialisation code, `conda deactivate`. For people who use anaconda extensively, but need to temporarily switch to other manager like homebrew, just use this command. It effectively set the conda base environment to none, if you check `conda info`. For example, I have homebrew pip3 installed `ipython`, after deactivated anaconda, `which ipython` gives `/usr/local/bin/ipython`. Then if `conda activate`, the `ipython` will have path `/Users/frank/anaconda3/bin/ipython`. Magic indeed – zrfrank Feb 26 '19 at 10:18
  • Additionally, I've tried the `pyenv` route extensively, but complicated and less effective. The `pyenv` can manage different versions of anaconda/miniconda as a `python version`, then use the pyenv to setup a virtual environment use anaconda. I feel it is a bit overkill. Also anaconda will be nested in the `pyenv` folder with other python versions, then one would manually change the anaconda path in some IDEs and affects the shell autocompletion. Moreover, `pyenv` still have the problem causing brew doctor to throw warning (normally don't break package though). I wouldn't recommend this path. – zrfrank Feb 26 '19 at 10:25
  • There is no reason why the additional comments above can not be turned into a second posted answer. Just a thought. I think this is about as close to a full answer as is going to be. Thanks both you. – Cam_Aust Feb 28 '19 at 04:20