What is the best way to Install Conda on MacOS (Apple/Mac)? - python

What is the recommended approach for installing Anaconda on Mac?
I tried with brew cask install anaconda which after a while returns anaconda was successfully installed!.
After that - trying conda command returns command not found: conda.
Is there any post step installation that needs to be done?
And what is recommended way to install Conda on MacOS?

brew install anaconda
export PATH="/usr/local/anaconda3/bin:$PATH"

I would say that the recommended way to install anaconda is to use the official anaconda installer, which can be downloaded from the link I just posted. I've done it several times, never had a problem, and it walks you through it (including an option to automatically add it to your PATH).

New answer using only the terminal for mac zsh
This is how I did it only using the terminal and apple's now default zsh:
# - 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: How do I use Conda in on Homebrew Python system?
Old answer
I don't know about other people but I've had issue downloading conda/miniconda etc for a few hours now. For some reason it decided to install at ~/opt when using the graphical installer (i.e. the .dmg file). I've been through the uninstall here How to uninstall Anaconda completely from macOS and additionall did an rm -rf ~/opt command. Seems that without this its not actually uninstalled (you might also have to change your PATH or .bash_profile or .bashrc until your path is virigin again before you start your re-installation installation). Seems that using the command line installer is what works:
Anaconda3 will now be installed into this location:
/Users/brandBrandoParetoopareto/anaconda3
- Press ENTER to confirm the location
- Press CTRL-C to abort the installation
- Or specify a different location below
[/Users/brandBrandoParetoopareto/anaconda3] >>>
PREFIX=/Users/brandBrandoParetoopareto/anaconda3
Unpacking payload ...
Collecting package metadata (current_repodata.json): done
Solving environment: done
So for that download it from the official link then do:
sh Anaconda3-2020.02-MacOSX-x86_64.sh
do sh I believe is the right thing because I might have had issue in the past when I did bash instead...plus if you are using a different shell like zsh I am not sure what you'd need to do, but I'd get sh would be safest.
After the installation is done you should do:
conda init <SHELL-NAME>
so that conda is initialized correctly (so far that seems to only modify my .bash_profile and my PATH variable). Unfortunately, it seems the previous uninstallation attempts didn't remove the code the previous conda init had added from my .bash_profile so I removed it manually using vim.
This is what I get after doing that:
conda init bash
no change /Users/brandBrandoParetoopareto/anaconda3/condabin/conda
no change /Users/brandBrandoParetoopareto/anaconda3/bin/conda
no change /Users/brandBrandoParetoopareto/anaconda3/bin/conda-env
no change /Users/brandBrandoParetoopareto/anaconda3/bin/activate
no change /Users/brandBrandoParetoopareto/anaconda3/bin/deactivate
no change /Users/brandBrandoParetoopareto/anaconda3/etc/profile.d/conda.sh
no change /Users/brandBrandoParetoopareto/anaconda3/etc/fish/conf.d/conda.fish
no change /Users/brandBrandoParetoopareto/anaconda3/shell/condabin/Conda.psm1
no change /Users/brandBrandoParetoopareto/anaconda3/shell/condabin/conda-hook.ps1
no change /Users/brandBrandoParetoopareto/anaconda3/lib/python3.7/site-packages/xontrib/conda.xsh
no change /Users/brandBrandoParetoopareto/anaconda3/etc/profile.d/conda.csh
modified /Users/brandBrandoParetoopareto/.bash_profile
==> For changes to take effect, close and re-open your current shell. <==
if you are using vs-code integrated terminal like I am you need to press the trash can button. Doing bash seems to NOT re-run your .bash_profile so make sure you do what it would consider "closing your terminal and re-opening it completely".
That should be all you need to do I believe. Perhaps you also need to make sure you have the most recent version of mac OS.
Extra tips hints
Make sure conda init modified your .bash_profile correctly. For me for some reason it added it's stuff AFTER it ran my .bashrc and thus when my .bashrc tried activating my environment it wouldn't do it as it would say conda wasn't initialized correctly (and thus nio matter how many times I re-ran conda init <SHELL> it wouldn't fix it. I don't know why that happened but that's how it was.
I avoided the dmg/graphical installation since it seemed to install it at non-standard places ~/opt
If conda is still acting weird it might be because of the way your .bashrc modifies the PATH env variable. What worked for me was removing lines that modified my path in .bashrc (AND having the code conda init added before my .bashrc was ran).
inspired from:
https://askubuntu.com/questions/505919/how-to-install-anaconda-on-ubuntu/1412558#1412558
https://docs.conda.io/projects/conda/en/latest/user-guide/install/linux.html
mac provides the nice renaming and downloading to location: https://docs.conda.io/projects/conda/en/latest/user-guide/install/macos.html
How to install wget in macOS?

After installation using the graphical installation, everything sits in the ~/opt directory, as mentioned in some previous answers. If this is OK for you, all you need to do to use the command line conda is add ~/opt/anaconda3/bin in your path. This can be done by adding
export PATH="${PATH}:~/opt/anaconda3/bin"
at the end of your rc file (~/.zshrc or ~/.bashrc).

Related

conda disappeared, command not found - corrupted .zshrc

All of the sudden, my terminal stopped recognizing the 'conda'. Also the VS Code stopped seeing my environments.
All the folders, with my precious environments are there (/opt/anaconda3), but when I type conda I get:
conda
zsh: command not found: conda
I tried install conda again (from .pkg) but it fails at the end of installation (no log provided).
How can I clean it without losing my envs?
I use Apple M1 MacBookPro with Monterey.
To recover conda if it has disappeared and you're getting a "command not found" error, follow these steps:
Check if conda is installed on your system by running the command:
which conda
If the above command doesn't return anything, you may need to add the path to your conda installation to your PATH environment variable. To find the path, run the following command:
find / -name conda 2>/dev/null
Add the path to your .bashrc or .bash_profile file:
export PATH="/bin:$PATH"
Restart your terminal or run the following command to reload your environment variables:
source ~/.bashrc
Try running conda again to see if it's working.
If conda is still not working, it may have been uninstalled or moved. In that case, you can reinstall conda from the Anaconda website or from the Miniconda website.
For some reason my .zshrc file was corrupted after some operations.
This prevented terminal to call conda init and in general, to have 'conda' call understandable.
What is more - this prevented installing any condas, minicondas, minoforge. Both from .pkg and .sh - annoyingly - without any log, information - just crash and goodbye.
I cleared both .zshrc' and .bash_profile` and then it helped - I managed to install minigorge and have my 'conda' accessible from terminal.
Unfortunately, in the process I removed all my previous 'envs'.

I have installed MSYS2 and Anaconda3, then how can I use conda on MSYS2?

I want to complie a fortran file on Win10, just like
python3 -m numpy.f2py -c -m h3plus h3plus.f90
But python in MSYS2 doesn't contain NumPy, so I try to use conda, but I don't know how to use conda on MSYS2.
If you don't have anaconda/miniconda already installed on your windows machine, do that by downloading the proper windows installer.
If conda is already installed on the windows side, all you have to do is initialize conda for MSYS2's bash. To do this, edit .bash_profile and append something like the following:
# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
eval "$('/c/Users/John/miniconda3/Scripts/conda.exe' 'shell.bash' 'hook')"
# <<< conda initialize <<<
Make sure you replace the path on the 3rd line with the path to conda.exe on your machine. After that close and reopen your MSYS2 terminals.
If you're using a shell other than bash, you can inspect the output of conda init --all --dry-run --verbose in order to find the corresponding init script.

How to get rid of (base) environment prefix shown in terminal

I have quite some problems using python on my Mac. I need different versions from 3.5 to 3.7 and multiple packages for data science. Due to various instructions on the web I ended up installing python 3.6 itself, anaconda, pipenv and maybe more stuff I can't even remember.
I suppose there is no other way to eliminate this mess than to format everything and start over. Currently my terminal is showing some sort of prefix for the environment in the terminal. Something like:
(base) user#machine:~$:
How can I at least get rid of this environment prefix? It appeared after installing pipenv, which seems to have taken over my previous anaconda environments. I fear those vanish to when uninstalling pipenv.
The deactivate command alone will get you out of the currently activated virtual environment.
(base) user#machine:~$:
(base) user#machine:~$: deactivate
user#machine:~$:
As far as I know, this works across all operating systems.
Found the problem: Anaconda edited the .bash_profile which gets executed on the mac for each new terminal. I deleted the anaconda entry and the base prefix is gone.
Also, for anyone that is using zsh and Anaconda.
You can remove the entry Anaconda makes from the ~/.zshrc file in addition to the conda deactivate
Conda can be configured with command conda config
This command will remove message about the current environment:
conda config --set changeps1 no
This command will add messages about the current environment:
conda config --set changeps1 yes
https://conda.io/projects/conda/en/latest/user-guide/configuration/use-condarc.html#change-command-prompt

Conda is corrupted after pip install conda

My conda is corrupted after I run command "pip install conda". Is there any way to recover it ? Thanks
Here's the error I see when running conda command
ERROR: The install method you used for conda--probably either `pip install conda`
or `easy_install conda`--is not compatible with using conda as an application.
If your intention is to install conda as a standalone application, currently
supported install methods include the Anaconda installer and the miniconda
installer. You can download the miniconda installer from
https://conda.io/miniconda.html.
Simply, follow the instructions given in the error:
Download miniconda, then run the script file by typing following command: bash <file_name.sh> e.g.
bash Miniconda3-latest-Linux-x86_64.sh.
Now reopen the terminal for the changes to take effect.
If conda is already installed on your system, you can reinstall it with the -f force option, for example,
bash Miniconda3-latest-Linux-x86_64.sh -f
To test your installation, enter the command conda --version. If installed correctly, you will see the version of conda installed.
miniconda: https://conda.io/en/latest/miniconda.html
conda troubleshooting: https://conda.io/docs/troubleshooting.html
If you are facing this problem in Virtual Machine (VM) then you have to activate the main environment by running below line of code:
source /anaconda_installation_folder_path/bin/activate
Once you are in your main environment you can work with conda.
TL;DR: nothing is corrupted, the message you're seeing is a hardcoded stub and could be fixed.
conda package manager actually can be used with regular python installation.
Update: I've been tinkering with the described method and found that you should use conda install --dry-run ... to see changes that are going to happen. Some conda packages depend on other python version, which would overwrite the installed one. There's might be a solution for this with changing conda channels or using virtualenv. I also found that --dry-run doesn't work when using local package archives.
I'll show you how to run cudatoolkit 9.1 without any Anaconda and python-3.6-amd64. I'm using cuda 9.1 from here.
Since conda is artificially tethered with Anaconda, you have to untie them.
I recommend you to backup up python installation directory you'll be working with (or use virtualenv).
Install menuinst dependency.
At the moment, it's broken from PyPi, so get if from
github. Build it and install python setup.py install
This package is problematic also in Anaconda distribution. It triggers series of requests for admin rights every time, which should be suppressed with conda ... --no-shortcuts option.
pip install pypiwin32, dependency of (1)
pip install conda, requires (1)
Move to python installation directory. ./Scripts/conda.exe should exist.
Move to ./Lib/site-packages/conda
Search directory recursively for pip_warning substring in following TEXT file types: .py, .json, .txt
Replace matching substrings pip_warning with main
Don't forget to abide the syntax of file types you'd be editing.
Now open the ./Scripts/conda.exe executable in any hex-editor and
find pip_warning, carefully overwrite it with main and wipe the
rest with spaces until bytes import main
Check for file size not have changed.
Remove any __pycache__ dirs if found in ./Lib/site-packages/conda
If you only need working conda without cuda, you're done here.
Run conda install mkl, pip install llvmlite numpy
Download packages cudatoolkit-9.1-0.tar.bz2
and numba-0.36.2.tar.bz2
and run
conda install cudatoolkit-9.1-0.tar.bz2
conda install numba-0.36.2-***.tar.bz2
Wait a little while unpacking finished.
Now try these examples, they should work and your gpu monitor show some activity. conda ... commands also do work.
With Linux, I guess instructions are the same, just would be .sh or ELF in place of .exe.
In my case, what worked was:
pip uninstall conda
and then installing miniconda
Download miniconda, then run the script file by typing following command: bash <file_name.sh> e.g. bash Miniconda3-latest-Linux-x86_64.sh -u
'-u' : update tag, used if the original conda bash paths get lost due to certain modifications in the .bashrc file

Trouble Installing Python with Framework-style Build (OS X)

In attempting to get started learning and developing python, I've tried to follow the Python Guide to installing python on OS X, but haven't found it particularly "noob friendly." I have a new MacBook (Mtn. Lion - OS X 10.8.3) wich comes with Python 2.7.2 built in. But the guide advises installing a "framework-style build" via homebrew. So:
I installed homebrew via ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"
Then it tells you to add homebrew to the top of your PATH by adding it to your ~/.bashrc file. ls -a showed that I did not have a ~/.bashrc file in my home directory. After searching Stack Overflow on how to do that, I ran nano ~/.bashrc, and inserted the line export PATH=/usr/local/bin:$PATH to the file and saved the file.
I then ran brew install python --framework and the install completed.
Then, the guide says to "add the new Python scripts directory to your PATH" so, I'm assuming that means I need to add the line it provides to my ~/.bashrc file also. So, I added export PATH=/usr/local/share/python:$PATH to my ~/.bashrc file above my previous entry.
Finally, this is where I run into trouble, it says to easy_install pip. However, when I do that I get an error 13.
So, here are the things I need some help with.
Was I correct in my assumptions about how to add homebrew and python scripts to my PATH?
Did I do something wrong or do I just need to use sudo to install pip? (I'm really sorry if the answer is already on this page but even those answers don't make total sense to me and I want to be careful and not screw something up)
After installing the framework-style build of python (which I believe was the current 2.7.3), how come running python in my terminal still shows v2.7.2?
Thanks! I appreciate any help.
I've tried to follow the Python Guide to installing python on OS X,
but haven't found it particularly "noob friendly.
Yes, I think it is misleading/outdated.
Then it tells you to add homebrew to the top of your PATH by adding it
to your ~/.bashrc file. ls -a showed that I did not have a ~/.bashrc
file in my home directory. After searching Stack Overflow on how to do
that, I ran nano ~/.bashrc, and inserted the line export
PATH=/usr/local/bin:$PATH to the file and saved the file.
On the Mac, just use ~/.profile
I then ran brew install python --framework and the install completed.
I think you don't need the --framework option unless you want to replace your Mac OS default installation and need an Mac OS Framework-style directory layout. There is no need to replace it though, the homebrew installation will take precedence anyway.
Then, the guide says to "add the new Python scripts directory to your
PATH" so, I'm assuming that means I need to add the line it provides
to my ~/.bashrc file also. So, I added export
PATH=/usr/local/share/python:$PATH to my ~/.bashrc file above my
previous entry.
Again, do it in ~/.profile. And don't forget to do a
source ~/.profile
otherwise the changes will only become active in any new terminal window, not the one you are currently using.
Finally, this is where I run into trouble, it says to easy_install
pip. However, when I do that I get an error 13.
The error shows that you try to install it your Mac OS system's default Python library (rather than in /usr/local, homebrew style), which would require root privileges. Just don't.
Also, with homebrew python, pip is already installed.
Check your path:
$ which pip
/usr/local/bin/pip
$ ls -l /usr/local/bin/pip
[..] /usr/local/bin/pip -> ../Cellar/python/2.7.3/bin/pip
Added bonus: Then do
pip install virtualenv
and use that.
And to your questions:
Was I correct in my assumptions about how to add homebrew and python
scripts to my PATH?
Yes, but use .profile and do a source .profile afterwards.
Did I do something wrong or do I just need to use sudo to install pip?
(I'm really sorry if the answer is already on this page but even those
answers don't make total sense to me and I want to be careful and not
screw something up)
You don't need sudo with homebrew, and pip is installed automatically with homebrew python.
After installing the framework-style build of python (which I believe
was the current 2.7.3), how come running python in my terminal still
shows v2.7.2?
Probably PATH not correct, do echo $PATH and check that it is correct. That is unrelated to being "framework-style" or not, though.
If you installed python with homebrew, you should already have pip installed. Try running
pip --version
to see whether and where pip is installed. Hopefully it's in a /usr/local/... path where your other homebrew things live.
Also before you install too much more with homebrew be sure to run these commands:
brew update
brew doctor
Good luck!

Categories

Resources