Reputation: 4640
I downloaded conda, however I would like to use pip and a regular python version (homebrew) for a different purpose, is it ok if I install python and pip via brew and then I install conda?
Update
after installing miniconda I tried to install python via homebrew and both python versions crashed. How can I install miniconda and then python via homebrew?
Upvotes: 6
Views: 2996
Reputation: 31
As of 2019, Amit Singh's comment is slightly out of date (and the link is broken). I had the same issue previously, but needed to install conda to work on a specific project with a collaborator. I did this using miniconda, but it should work with Anaconda as well.
After installing conda, this is added to ~/.bash_profile (or .bashrc):
added by Miniconda3 4.5.12 installer
>>> conda init >>>
!! Contents within this block are managed by 'conda init' !!
__conda_setup="$(CONDA_REPORT_ERRORS=false '/Users/<user>/miniconda3/bin/conda' shell.bash hook 2> /dev/null)"
if [ $? -eq 0 ]; then
\eval "$__conda_setup"
else
if [ -f "/Users/<user>/miniconda3/etc/profile.d/conda.sh" ]; then
. "/Users/<user>/miniconda3/etc/profile.d/conda.sh"
CONDA_CHANGEPS1=false conda activate base
else
\export PATH="/Users/<user>/miniconda3/bin:$PATH"
fi
fi
unset __conda_setup
<<< conda init <<<
It basically automatically activates a base conda environment and puts you in it when you start a new shell. This adds conda's python, and other software, to your path. Any tools looking for system/homebrew install programs such as python will get the conda versions instead if they exist. This can create problems if you are trying to use the homebrew versions of things.
This whole block can be safely deleted. Instead, add:
. /Users/<user>/miniconda3/etc/profile.d/conda.sh
to you ~./bash_profile. This calls a script which creates bash functions for conda, conda activate, and conda deactivate and sets some environment variables. Importantly, it doesn't active the base environment (the default, global conda environment) or change your path.
You can now create a conda environment for your project and install whatever you need into that:
conda create -n my_project python R jupyter # Whatever packages you need
conda activate my_project
# do some stuff
conda deactivate # leave the environment
# do unrelated stuff without issues
If you do want to use the default (root) environment, it can be activated like any other:
conda activate root
# do some stuff
conda deactivate
I hope that helps!
Upvotes: 3
Reputation: 3063
From Anaconda Troubleshoot FAQ, following methods can be employed :
Edit your .bash_profile
and .bashrc
files so that the conda binary directory, such as ~/miniconda3/bin
, is no longer added to the PATH environment variable. You can still run conda
activate
and deactivate
by using their full path names, such as ~/miniconda3/bin/conda
.
You may also create a folder with symbolic links to conda
, activate
and deactivate
, and then edit your .bash_profile
or .bashrc
file to add this folder to your PATH. If you do this, running python
will invoke the system Python, but running conda
commands, source activate MyEnv
, source activate root
, or source deactivate
will work normally.
After running source activate
to activate any environment, including after running source activate root
, running python
will invoke the Python in the active conda environment.
Upvotes: 2
Reputation: 7157
Conda creates language-agnostic environments natively whereas pip relies on
virtualenv
to manage only Python environments Though it is recommended to always useconda
packages,conda
also includes pip, so you don’t have to choose between the two. For example, to install a python package that does not have aconda
package, but is available through pip.
You can also use pip
within your conda
environment:
conda install pip
pip <pip command>
or
conda install -n testenv pip
source activate testenv
pip <pip command>
You can also add pip to default packages of any environment so it is present each time so you don't have to follow the above snippet.
Upvotes: 3