Zsh: Conda/Pip installs command not found

172,232

Solution 1

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.

Solution 2

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!!! γŠ—οΈ πŸŽ‰πŸŽ‰πŸŽ‰

Solution 3

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.

Solution 4

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:

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

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"

Solution 5

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.

Share:
172,232

Related videos on Youtube

Architek1
Author by

Architek1

Learning...Processing and JavaScirpt with with Node.js throw in just to make it a little more difficult.

Updated on December 17, 2021

Comments

  • Architek1
    Architek1 over 2 years

    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?

  • truongnm
    truongnm over 6 years
    I pasted the path from my bash_profile, and don't forget to source ~/.zshrc
  • wi3o
    wi3o over 6 years
    > source ~/.zshrc definitely helps!
  • AZhao
    AZhao over 6 years
    docs.anaconda.com/anaconda/faq#id9 could it be the docs themselves are wrong? I spent an hour until i stumbled upon this.
  • Joel Colucci
    Joel Colucci about 6 years
    Thanks copying the PATH in ~/.bash_profile to ~/.zshrc worked for me.
  • Piotr Jankiewicz
    Piotr Jankiewicz almost 6 years
    The root direcotory! Thank you.
  • Aus_10
    Aus_10 over 4 years
    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.
  • Kyle Frye
    Kyle Frye over 4 years
    If anyone is here dealing with reinstalling after the Catalina OS update this is probably what you're looking for.
  • hzitoun
    hzitoun over 4 years
    source ~/.zshrc is not enough, needed indeed to add source ~/.bash_profile so thanks!
  • James N
    James N over 4 years
    this worked for me on Macbook pro-2019 with macOS Catalina, thank you
  • redHair
    redHair about 4 years
    Thanks for the saving my time;)
  • nkirit
    nkirit about 4 years
    This is no longer working in 2020 - add this to first line of ~/.zshrc export PATH="/usr/local/anaconda3/bin:$PATH"
  • Pieter
    Pieter almost 4 years
    macbook air 2019 model, catalina: works perfectly, many thanks
  • matthewpliddy
    matthewpliddy over 3 years
    If you install anaconda for all users (like me) use source /opt/anaconda3/bin/activate
  • goe
    goe over 3 years
    Perfect solution with OSX 11
  • Ben2209
    Ben2209 over 3 years
    this is not the cleanest solution. There are better solutions like the one of @edwardyaho or mine below.
  • Bright Chang
    Bright Chang about 3 years
    Great explanation! Thank you!
  • Adrian Aley
    Adrian Aley almost 3 years
    This is for MacOS but may work for others as well.
  • Ribena
    Ribena almost 3 years
    WARNING. This is not without risk. Doing this completely messed up my prompt. But my faulty for following steps devoid of an explanation.
  • Kearney
    Kearney over 2 years
    on my basrc, it is [ -f /opt/miniconda3/etc/profile.d/conda.sh ] && source /opt/miniconda3/etc/profile.d/conda.sh
  • Tack_Tau
    Tack_Tau over 2 years
    This works perfectly on M1 Mac with BigSur 11.6, thanks!
  • user1207289
    user1207289 over 2 years
    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 list
  • Hugo Lemieux-Fournier
    Hugo Lemieux-Fournier about 2 years
    The default .bash_profile is now called .profile which can be seen in the HOME directory.
  • seeker_after_truth
    seeker_after_truth about 2 years
    How is this actually working? And @Ben2209, how is this not the cleanest solution/what is wrong with it?
  • Ben2209
    Ben2209 about 2 years
    @seeker_after_truth 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.
  • Nurseyit Tursunkulov
    Nurseyit Tursunkulov about 2 years
    perfect solution
  • Sukanya Pai
    Sukanya Pai almost 2 years
    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.
  • Charlie Parker
    Charlie Parker almost 2 years
    weird, why do we need to run bash_profile?
  • Charlie Parker
    Charlie Parker almost 2 years
    why aren't you running .bach_profile?
  • Charlie Parker
    Charlie Parker almost 2 years
    why aren't you running .bach_profile?
  • Charlie Parker
    Charlie Parker almost 2 years
    why aren't you running .bach_profile?
  • Charlie Parker
    Charlie Parker almost 2 years
    how do I find the path to source /Users/my_username/opt/anaconda3/bin/activate not sure where conda installed it's stuff...
  • n1tk
    n1tk almost 2 years
    Because question is tagged as zsh …