Zsh: Conda/Pip installs command not found
Asked Answered
G

29

156

So I installed Anaconda and everything is working. After I installed it I decided to switch to oh-my-zsh. I am now getting:

zsh: command not found: conda

when trying to use pip or conda installs

echo $ZSH_VERSION

5.0.5

I have added to my zshenv.sh

export PATH ="/Users/Dz/anaconda/bin:$PATH"

What is it that I'm missing?

Genitalia answered 24/7, 2015 at 16:19 Comment(2)
I think this is all you really need to answer this: source ~/miniconda/bin/activate then run conda init zsh assuming you installed conda. If not check this: #49118777Dagall
set the source using same command for as suggested by @Charlie Only change for anaconda installation is use this command : source ~/opt/anaconda3/bin/activate path /opt/anaconda3 should be your installed location of anaconda please check and modify.Downstairs
G
30

It appears that my PATH is broken in my .zshrc file.

Open it and add :

export PATH="$PATH;/Users/Dz/anaconda/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Users/Dz/.rvm/bin"

Doh! Well that would explain everything. How did I miss that little semicolon? Changed:

export PATH="$PATH:/Users/Dz/anaconda/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Users/Dz/.rvm/bin"

source ~/.zshrc
echo $HOME
echo $PATH

We're good now.

Genitalia answered 24/7, 2015 at 18:56 Comment(1)
why aren't you running .bach_profile?Dagall
L
200

I found an easy way. Just follow below steps:

  1. in terminal, enter vim ~/.zshrc enter image description here
  2. add source ~/.bash_profile into .zshrc file enter image description here
  3. and then in terminal, enter source ~/.zshrc enter image description here

Congratulation for you!!! ㊗️ 🎉🎉🎉

Leif answered 26/4, 2019 at 2:47 Comment(15)
source ~/.zshrc is not enough, needed indeed to add source ~/.bash_profile so thanks!Diplomatist
this worked for me on Macbook pro-2019 with macOS Catalina, thank youAubergine
This is no longer working in 2020 - add this to first line of ~/.zshrc export PATH="/usr/local/anaconda3/bin:$PATH"Centriole
macbook air 2019 model, catalina: works perfectly, many thanksConcerning
Perfect solution with OSX 11Chincapin
this is not the cleanest solution. There are better solutions like the one of @edwardyaho or mine below.Chiastic
WARNING. This is not without risk. Doing this completely messed up my prompt. But my faulty for following steps devoid of an explanation.Anemophilous
The default .bash_profile is now called .profile which can be seen in the HOME directory.Gerund
How is this actually working? And @Ben2209, how is this not the cleanest solution/what is wrong with it?Simonnesimonpure
@Simonnesimonpure Sourcing .bash_profile when you actually are not using bash but zsh is some kind of workaround. Conda offers a command that inserts the right code in the .zshrc directly. See my answer below.Chiastic
This messed up my terminal and the bash was not getting exited after "Process completed" because apparently adding this line results in infinite loop and the terminal hangs.Stepup
weird, why do we need to run bash_profile?Dagall
no this is dangerous. Better open .bashrc and copy the conda specific commands and paste in .zshrc.Cutback
This only works if your .bashrc isn't doing anything incompatible with zsh, so as others say, it's risky.Minnie
This is a lifesaver, want to give it a 1000 upvotes and bookmark it for life !Angelikaangelina
C
183

If you are on macOS Catalina, the new default shell is zsh. You will need to run source /bin/activate followed by conda init zsh. For example: I installed anaconda python 3.7 Version, type echo $USER to find username

source /Users/my_username/opt/anaconda3/bin/activate

Follow by

conda init zsh

or (for bash shell)

conda init

Check working:

conda list

The error will be fixed.

Calces answered 7/2, 2020 at 0:13 Comment(10)
If you install anaconda for all users (like me) use source /opt/anaconda3/bin/activateCastra
This works perfectly on M1 Mac with BigSur 11.6, thanks!Loach
After running above commands you'll start to get (base) in front of your zsh when a fresh zsh window is opened. To remove that run conda config --set auto_activate_base false . Open new zsh and try conda listVelvetvelveteen
why aren't you running .bach_profile?Dagall
how do I find the path to source /Users/my_username/opt/anaconda3/bin/activate not sure where conda installed it's stuff...Dagall
@CharlieParker You should have had the option to specify this during installation. The default for me was /Users/me/anaconda3, but you should be able to find where it is simply by searching in Finder :)Ommiad
Using Mac rosetta, the binaries are in /usr/local/anaconda3/binCataract
Thanks. It worked from me on MAC "source /Users/my_username/opt/anaconda3/bin/activate"Gormand
installing by homebrew: source /opt/homebrew/anaconda3/bin/activateClarence
How to automatically run source /Users/x/anaconda3/bin/activate? It works for me, however, it's a bit tedious to do this every time I open a new terminal window... Tried to add it in the ~./zshrc but that did not workVend
A
54

As of today Nov 4, 2018 all the following methods works, install the zsh with:

sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

Not recommending brew installation for zsh:

brew install zsh zsh-completions 

P.S: Tried with with brew and brew install under the root and is not an wise idea to do so due the security and all time anything related will need to be started under sudo so better is to stick with curl or wget.

to make work conda in OS X with oh-my-zsh installed is to add path as following and will work.

Find the python paths so can see if you installed Anaconda2 or Anaconda3: where python or which python will result in similar output:

/usr/bin/python
/Users/"username"/anaconda/bin/python # # previous path for anaconda
/Users/"username"/anaconda3/bin/python # # previous path for anaconda3
/Users/"username"/opt/anaconda/bin/python # # for current path anaconda
/Users/"username"/opt/anaconda3/bin/python # # for current path for anaconda3

one line config command for Anaconda:

echo -e '# >>> anaconda conda config >>> \nPATH="$HOME/opt/anaconda3/bin:$PATH"' >> ~/.zshrc && source ~/.zshrc && conda init

For using with miniconda for one line config command for arm64 : Apple Silicon miniconda3 (M1 & M2), part of installation for MPS acceleration tensorflow-metal, pytorch ):

Note: Anaconda do not recommend to add manually paths per following: Should I add Anaconda to the macOS or Linux PATH?

We do not recommend adding Anaconda to the PATH manually. During installation, you will be asked “Do you wish the installer to initialize Anaconda3 by running conda init?” We recommend “yes”. If you enter “no”, then conda will not modify your shell scripts at all. In order to initialize after the installation process is done, first run source /bin/activate and then run conda init.

Note:

Replace <path-to-anaconda> with the actual path of your installed Anaconda file.

What is the default path for installing Anaconda?

If you accept the default option to install Anaconda on the “default path” Anaconda is installed in your user home directory:

  • Windows 10: C:\Users<your-username>\Anaconda3\

  • macOS: /Users//anaconda3 for the shell install, ~/opt for the graphical install. See installing on macOS.

  • Linux: /home//anaconda3

If your username includes spaces, as is common on Windows systems, you should not accept the default path. See In what folder should I install Anaconda on Windows?

I already have Python installed. Can I install Anaconda?

You do not need to uninstall other Python installations or packages before installing Anaconda. Even if you already have a system Python, another Python installation from a source such as the macOS Homebrew package manager and globally installed packages from pip such as pandas and NumPy, you do not need to uninstall, remove, or change any of them.

Install Anaconda or Miniconda normally. There is no need to set the PYTHONPATH environment variable.

To see if the conda installation of Python is in your PATH variable:

  • On macOS and Linux, open the terminal and run echo $PATH.

  • On Windows, open an Anaconda Prompt and run echo %PATH%.

To see which Python installation is currently set as the default:

  • On macOS and Linux, open the terminal and run which python.
  • On Windows, open an Anaconda Prompt and run where python.

To see which packages are installed in your current conda environment and their version numbers, in your terminal window or an Anaconda Prompt, run conda list.

For detailed info on adding manually see below info:

Finding your Anaconda Python interpreter path

vi ~/.zshrc or gedit ~/.zshrc

Anaconda updated to use similar to Anaconda Enterprise edition paths: /opt/... @update Dec 2021: For Anaconda3 at field # User configuration add:

PATH="$HOME/opt/anaconda3/bin:$PATH"

For Anaconda: at field # User configuration add:

`PATH="$HOME/anaconda/bin:$PATH"`

For Anaconda2 at field # User configuration add:

  `PATH="$HOME/anaconda/bin:$PATH"`

For Anaconda3 at field # User configuration add:

`PATH="$HOME/anaconda3/bin:$PATH"`

or replace "username" with your username:

`PATH="/Users/"username"/anaconda3/bin:$PATH`

According to documentation Installing on macOS we add add in ~/.zshrc instead of .bashrc or .bash_profile

  • Add export PATH="/<path to anaconda>/bin:$PATH" in ~/.zshrc

  • Or set the PATH variable: export PATH="/<path to anaconda>/bin:$PATH"

Replace “<path to anaconda>” with the actual path to your Anaconda installation.

This methods are working on ubuntu/Centos7/MacOS as well (just close/reset the terminal once you are completing the changes) than just type conda to test.


Per @truongnm comment just source after adding the path: "I pasted the path from my bash_profile, and don't forget to source ~/.zshrc"

Ain answered 13/2, 2016 at 2:42 Comment(4)
I pasted the path from my bash_profile, and don't forget to source ~/.zshrcCrudden
> source ~/.zshrc definitely helps!Unaccompanied
why aren't you running .bach_profile?Dagall
Because question is tagged as zsh …Ain
G
30

It appears that my PATH is broken in my .zshrc file.

Open it and add :

export PATH="$PATH;/Users/Dz/anaconda/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Users/Dz/.rvm/bin"

Doh! Well that would explain everything. How did I miss that little semicolon? Changed:

export PATH="$PATH:/Users/Dz/anaconda/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Users/Dz/.rvm/bin"

source ~/.zshrc
echo $HOME
echo $PATH

We're good now.

Genitalia answered 24/7, 2015 at 18:56 Comment(1)
why aren't you running .bach_profile?Dagall
F
27

The anaconda installer automatically writes the correct PATH into the ~/.bash_profile file. Copy the line to your ~/.zshrc file, source it with source ~/.zshrc and you're good to go.

Fifteenth answered 13/1, 2018 at 12:37 Comment(4)
Thanks copying the PATH in ~/.bash_profile to ~/.zshrc worked for me.Void
This worked for me. Thanks. Just for clarity: I copied there are several lines in .bash_profile installed by anaconda that I copied and put into .zshrc. Everything worked as expected afterwards.Kathykathye
on my basrc, it is [ -f /opt/miniconda3/etc/profile.d/conda.sh ] && source /opt/miniconda3/etc/profile.d/conda.shYippie
This answer is gold.Nisus
D
19

Answer for macOS 11 (Big Sur) in 2021

After installing Anaconda, run:

source /opt/anaconda3/bin/activate
conda init zsh

then close and reopen the Terminal window. The shell prompt should have a (base) prefix.

NOTE: I found many articles online saying to update the PATH variable, but Anaconda actually recommends against doing so and running the two commands above instead, which they state in their documentation.

Source

Deputation answered 9/2, 2021 at 23:45 Comment(6)
Thanks, this is the cleanest solution for me!Gender
works on linux manjaro too, thanksDagnah
Same, worked well, thanks!Horseshoe
This should be the top scoring solution.Insensibility
this one is the best solution for me after migrate from bash to zshAubervilliers
I'm running OS 14.2.1. When I run the command above, I get source: no such file or directory: /opt/anaconda3/bin/activate. Any idea why?Landri
G
14

I had this problem on my Catalina OSX after I installed my Anaconda distribution as well.

This solution worked for me on macOS Catalina as of October 19, 2019

Step 1. Check if .bash_profile is available on your home folder, if not:

  • Go to Terminal
  • Type cd ~/ to go to your home folder (if you are not on your home folder)
  • Type touch .bash_profile to create your new file under the your home folder

Step 2. Check if file .zshrc is available on your home folder, if not:

  • Go to terminal and type nano ~/.zshrc

  • Type in the following line into the newly created .zshrc file: source ~/.bash_profile

  • Now to save the file in nano just hit ctrl+X.

  • It will prompt "Save modified buffer (ANSWERING "No" WILL DESTROY CHANGES)?". Just type in Y

Step 3. Check if .bash_profile and .zshrc files are created on your home folder. If yes, in terminal type in source ~/.zshrc

Glaikit answered 20/10, 2019 at 21:56 Comment(0)
N
14

You should do the following:
1. /home/$USER/anaconda/bin/conda init zsh (or /home/$USER/miniconda3/bin/conda init zsh if you use miniconda)
2. source ~/.zshrc (or just reopen terminal)

Why this answer is better than others?

  • You shouldn't reinvent the wheel: there is already command in conda to activate, all you need to do is to call conda with full path
  • Maybe ~/.bash_profile doesn't exist (my case, only ~/.bashrc)
  • You can have bash-specific config inside ~/.bash_profile
  • You don't need manually paste and export any pathes
Nelan answered 2/4, 2020 at 16:51 Comment(0)
P
11

This is all I had to add to add get anaconda working for zsh.

echo ". /anaconda3/etc/profile.d/conda.sh" >> ~/.zshrc
source ~/.zshrc
Petrolic answered 27/12, 2018 at 19:42 Comment(0)
C
10

If this problem occurs on a mac, then type the following commands:

source <path to conda>/bin/activate
conda init zsh

This will modify your zshrc accordingly (or create it if it does not exist).

This solution comes from the official anaconda doc.

Chiastic answered 30/6, 2020 at 6:42 Comment(0)
K
9

I just ran into the same problem. As implicitly stated inside the .zshrc-file (in your user-root-folder), you need to migrate the pathes you've already inserted in your .bash_profile, bashrc or so to resolve this.

Copying all additional pathes from .bash_profile to .zshrc fixed it for me, cause zsh now knows where to look.

#add path to Anaconda-bin
export PATH="/Users/YOURUSERNAME!!/anaconda3/bin:$PATH"

 #N.B. for miniconda use
export PATH="/Users/YOURUSERNAME!!!/miniconda3/bin:$PATH"

Depending on where you installed anaconda this path might be different.

Kalidasa answered 3/2, 2018 at 13:53 Comment(1)
If anyone is here dealing with reinstalling after the Catalina OS update this is probably what you're looking for.Extended
C
8

You need to fix the spacing and quotes:

export PATH ="/Users/Dz/anaconda/bin:$PATH"

Instead use

export PATH="/Users/Dz/anaconda/bin":$PATH
Chun answered 11/8, 2017 at 17:19 Comment(1)
docs.anaconda.com/anaconda/faq#id9 could it be the docs themselves are wrong? I spent an hour until i stumbled upon this.Danille
D
5

If anaconda is fully updated, a simple "conda init zsh" should work. Navigate into the anaconda3 folder using

cd /path/to/anaconda3/

of course replacing "/path/to/anaconda/" with "~/anaconda3" or "/anaconda3" or wherever the "anaconda3" folder is kept.

To make sure it's updated, run

./bin/conda update --prefix . anaconda

After this, running

./bin/conda init zsh

(or whatever shell you're using) will finish the job cleanly.

Dianoia answered 18/12, 2019 at 4:56 Comment(0)
A
4
  1. Find the right version of your anaconda

  2. Put it to ~/.zshrc via command vim ~/.zshrc

    • Anaconda 2 export PATH="/User/<your-username>/anaconda2/bin:$PATH"
    • Anaconda 3 export PATH="/User/<your-username>/anaconda3/bin:$PATH"
    • Or if you install Anaconda in root directory:
    • Anaconda 2 export PATH="/anaconda2/bin:$PATH"
    • Anaconda 3 export PATH="/anaconda3/bin:$PATH"
  3. Restart the zsh source ~/.zshrc

Apteral answered 26/2, 2018 at 4:15 Comment(1)
The root direcotory! Thank you.Stealthy
D
3

Key is to activate conda after you installed it from executing the official install (e.g. with sh or something). So this:

source ~/miniconda/bin/activate
conda init zsh

My whole installation:

# - 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:

Dagall answered 24/7, 2015 at 16:19 Comment(0)
U
3

MAC OS Users:

  1. brew install anaconda
  2. Add export PATH="/usr/local/anaconda3/bin:$PATH" to top of ~/.zshrc
  3. source ~/.zshrc OR restart terminal

Test it. Bingo Bango.

Unbidden answered 10/11, 2020 at 17:42 Comment(0)
P
2

I simply added the anaconda3 path to $PATH in .zshrc which did the trick for.

My environment : Catalina / clean Anaconda install / iTerm / zsh / oh-my-zsh

First locate your conda installation:

> find ~/ -name 'conda' -print

(on my system: ~/opt/anaconda3/bin/conda)

Then add that path to PATH in the .zshrc file

export PATH="opt/anaconda3/bin":$PATH
Puebla answered 2/7, 2020 at 13:5 Comment(0)
V
2

run the following script provided by conda in your terminal:

source /opt/conda/etc/profile.d/conda.sh - you may need to adjust the path to your conda installtion folder.

after that your zsh will recognize conda and you can run conda init this will modify your .zshrc file automatically for you. It will add something like that at the end of it:

# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/opt/conda/bin/conda' 'shell.zsh' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
    eval "$__conda_setup"
else
    if [ -f "/opt/conda/etc/profile.d/conda.sh" ]; then
        . "/opt/conda/etc/profile.d/conda.sh"
    else
        export PATH="/opt/conda/bin:$PATH"
    fi
fi
unset __conda_setup
# <<< conda initialize <<<

source: https://docs.conda.io/projects/conda/en/latest/user-guide/install/rpm-debian.html

Vanthe answered 4/12, 2020 at 10:6 Comment(0)
L
2

For Linux

  1. Open .bashrc
  2. Copy the code for conda initialize and paste it to .zshrc file
  3. Finally run source .zshrc
Logicize answered 28/1, 2021 at 10:22 Comment(1)
Great explanation! Thank you!Intrigue
R
1

Simply copy your Anaconda bin directory and paste it at the bottom of ~/.zshrc.

For me the path is /home/theorangeguy/miniconda3/bin, so I ran:

echo ". /home/theorangeguy/miniconda3/bin" >> ~/.zshrc

This edited the ~/.zshrc. Now do:

source ~/.zshrc

It worked like a charm.

Repetitious answered 6/3, 2020 at 19:51 Comment(0)
E
1
  1. Open your ~./bashrc
  2. Find the following code (maybe something similar) that launches your conda:

    # >>> conda init >>>
    # !! Contents within this block are managed by 'conda init' !!
    __conda_setup="$(CONDA_REPORT_ERRORS=false '/anaconda3/bin/conda' shell.bash hook 2> /dev/null)" if [ $? -eq 0 ]; then
        \eval "$__conda_setup" else
        if [ -f "/anaconda3/etc/profile.d/conda.sh" ]; then
            . "/anaconda3/etc/profile.d/conda.sh"
            CONDA_CHANGEPS1=false conda activate base
        else
            \export PATH="/anaconda3/bin:$PATH"
        fi fi unset __conda_setup
    # <<< conda init <<<

  1. source ~/.zshrc
  2. Things should work.
Expose answered 13/11, 2020 at 9:39 Comment(0)
H
1

If you are using an M1 mac or versions after macOS 11 then here's how you can go:

source /opt/anaconda3/bin/activate

conda init zsh

After this you can restart your shell and it will be working fine

Haugh answered 20/4, 2023 at 16:25 Comment(0)
A
0

So I discovered that in your ~/.zshrc file, there was a commented line,

# If you come from bash you might have to change your $PATH # export PATH=$HOME/bin:/usr/local/bin:$PATH

Just uncomment the export statement and all your previous bash_profile commands will also be there. If that comment does not exist, you can also just add that export statement to .zshrc file.

Afterdamp answered 22/3, 2020 at 18:4 Comment(0)
C
0

None of these solutions worked for me. I had to append bash environment to the zsh:

echo 'source ~/.bash_profile' >> ~/.zshrc
Craft answered 27/3, 2020 at 23:17 Comment(0)
G
0

Go to terminal PREFERENCES, then PROFILES tab, then under the STARTUP section within the SHELL tab, check the white boxes for RUN COMMAND and RUN INSIDE SHELL. Clear any text in the RUN COMMAND input area, then add the command below and restart the terminal:

source ~/.bash_profile; clear

Guv answered 13/5, 2021 at 2:59 Comment(1)
This is for MacOS but may work for others as well.Guv
W
0

TL;DR

Using this script will modify your .zshrc file (which is what we want, but just be warned).

Anytime you see a file with .*rc it means it is a run command that essentially runs some start up instructions, and in this case, stuff you need for your shell to know so it does what you want it to.

Assuming you have conda installed already, the following works:

$ source path/to/your/conda/activate
(base) $ conda init zsh

For example, the path to my particular conda installation is /Users/username/opt/miniconda3/bin/conda

So my shell commands looked like this:

$ /Users/username/opt/miniconda3/bin/activate
(base) $ conda init zsh

Details

You type conda into your shell running zsh and it gets mad:

$ zsh: command not found: conda

Your zsh shell does not come preconfigured to recognize conda. We know this because there is nothing in your .zshrc file to indicate it knows conda at all. You have to tell your shell (in this case zsh) that you want this to happen. The conda team knows this, so they made a command for such a need. But, first you have to activate conda manually like you would a virtualenv (don't worry about this last statement if it confuses you).

So you activate conda manually by using the source command:

$ source path/to/your/conda/activate
(base) $

Since paths can differ here, I used a made up path but your path probably looks something like /Users/username/opt/.../activate.

Next, you run a --dry-run of conda init because you do not want to modify things without knowing what you are modifying (in my opinion). An output example is shown below but it may not match yours:

(base) $ conda init zsh --dry-run
no change     /Users/username/opt/miniconda3/condabin/conda
no change     /Users/username/opt/miniconda3/bin/conda
...

If you are happy with what will change, run the same command without the --dry-run flag.

Finally, restart your shell. It should open with something like this:

(base) $

Now you can use conda as you like anytime you start up your shell.

Wax answered 25/7, 2022 at 21:34 Comment(0)
F
-1

I see a lot of good answers, but still I couldn't resolve the issues on Mac Sonoma 14. I recommend finding the path of the condo first and then exporting it or using it in the profile.

Find conda path

which conda 

Expected output

/usr/local/anaconda3/bin/conda

Now we have two options to set the PATH.

Option 1 - export the path only for the current shell

export PATH="/usr/local/anaconda3/bin:$PATH"

Option 2 - add the path to bash profile and execute source

nano ~/.bash_profile
export PATH="/usr/local/anaconda3/bin:$PATH" # add to .bash_profile
source ~/.bash_profile # read and execute the commands

And you're done 👏

Focalize answered 8/1 at 4:44 Comment(0)
H
-2

FYI for anyone having this same issue keep in mind that you need to make sure that you have the right version of anaconda in that export path:

anaconda2 or anaconda3 

Spent way too long on that minor issue.

Henandchickens answered 1/11, 2017 at 0:16 Comment(0)
A
-2

this solved it for me, and is sure to work add this to ~/.zshrc

export PATH=path_to_anaconda_bin:$PATH

the answer

Amphoteric answered 17/3, 2020 at 11:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.