17

I'm using Homebrew as my package general manager, and am using its Python and pip for software development, along with virtualenvs. For various reasons, I'd like to continue with this structure, but I need some software that is (apparently) easier to install using Conda.

Can I continue to use Homebrew+pip+virtualev and add Conda into the mix, ideally inside a virtualenv so that it doesn't affect my system as a whole? If so, how do I set up and use Conda in this way?


(Python: 2.7.11 (Homebrew); pip: 8.1.1; setuptools: 20.6.7; OS X: 10.11.4 (x86_64))

Community
  • 1
  • 1
orome
  • 45,163
  • 57
  • 202
  • 418
  • is using brew to install conda really advised? this seems to be the recomended thing to do https://docs.conda.io/projects/conda/en/latest/user-guide/install/macos.html? – Charlie Parker Jun 06 '22 at 16:18
  • perhaps this is a good link to follow/use: https://stackoverflow.com/questions/49118277/what-is-the-best-way-to-install-conda-on-macos-apple-mac and avoid brew? I didn't seem to need it and not sure if brew is trustable. If you think it is let me know! – Charlie Parker Jun 06 '22 at 17:46

3 Answers3

27

You can install Anaconda. Try brew install --cask anaconda. Follow the on-screen instructions you may want to add export PATH=/usr/local/anaconda3/bin:"$PATH" to your ~/.bash_profile or ~/.zsh file.

Using anaconda you can create virtual environments for python2 and python3. You can set up environments and then use commands like source activate py27 assuming py27 is an environment you created in python2.7 in anaconda. It even has GUI and CLI versions.

Every time I open my terminal, my .bash_profile and .zshrc get sourced. If you append the source line above, it will load with the version you need everytime. Every anaconda environment has its own pip as well. With Anaconda in the mix, you'd not really need virtualenv anymore but you can keep it if you want.

If you want to run the Anaconda Navigator GUI you can run it: open /usr/local/anaconda3/Anaconda-Navigator.app. You can use it to manage/create the environments and pip packages, etc.

Community
  • 1
  • 1
devssh
  • 1,184
  • 12
  • 28
  • Check out https://stackoverflow.com/questions/17386880/does-anaconda-create-a-separate-pythonpath-variable-for-each-new-environment#17407341 for how to `source activate` – devssh Nov 14 '17 at 15:54
  • 2
    I had to add this to my .bash_profile or .zshrc `export PATH="/usr/local/anaconda3/bin/:$PATH"` to get `source activate py36` to work – devssh Nov 14 '17 at 16:09
  • When installing `conda`, the last step is to offer to place the `conda` path in your `~/.bash_profile`. Even if you don't use Bash, say yes so that you can see what the correct `$PATH` setup is. – BallpointBen May 04 '18 at 19:12
  • What if you install the same software with both `brew` and `conda` - which version will take priority when launching? What about dependencies? What if I install some java program with `brew`, but `conda` java will be prioritized, will it work? I never tried running both *and* having both in the PATH, as I was worried about these kinds of conflicts. – jena Jan 14 '21 at 16:31
  • is using brew to install conda really advised? this seems to be the recomended thing to do https://docs.conda.io/projects/conda/en/latest/user-guide/install/macos.html? – Charlie Parker Jun 06 '22 at 16:18
2

I may be wrong but it sounds like the op is trying to figure out how to make a virtual environment for anaconda without overriding all their existing python stuff. At least that is what I was trying to do which led me here. I managed to find a rather inelegant solution that you can use if you really must have anaconda in its own env:

As devssh says, you can do a brew cask install anaconda but dont add the directory to your path, or it will override your python 2.7 and cause much sadness. Instead create a virtual environment like such (Im using virtual environment wrapper):

mkvirtualenv -p /usr/local/anaconda3/bin/python anaconda_env

now move all the stuff from anaconda bin into your virtualenv bin:

cp /usr/local/anaconda3/bin/* /Users/<you>/.virtualenvs/anaconda_env/bin/

This last is necessary because the anaconda dependencies were not installed with the environments pip so it doesnt know where to look for them.

bradimus
  • 825
  • 11
  • 25
  • is using brew to install conda really advised? this seems to be the recomended thing to do https://docs.conda.io/projects/conda/en/latest/user-guide/install/macos.html? – Charlie Parker Jun 06 '22 at 16:18
0

Perhaps using brew is not recommended but these commands should work

# - install python
# install brew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
#  install wget to get miniconda
brew install wget

# get miniconda
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-x86_64.sh -O ~/miniconda.sh
bash ~/miniconda.sh -b -p $HOME/miniconda

# source /Users/my_username/opt/anaconda3/bin/activate
source ~/miniconda/bin/activate
conda init zsh
conda update -n base -c defaults conda
conda install conda-build

conda create -n iit_synthesis python=3.9
conda activate iit_synthesis
#conda remove --name metalearning2 --all

inspired from:

Charlie Parker
  • 5,884
  • 57
  • 198
  • 323