CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'

avatar
Borislav Hadzhiev

Last updated: Apr 10, 2024
3 min

banner

# CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'

shell
⛔️ CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'. To initialize your shell, run $ conda init <SHELL_NAME> See 'conda init --help' for more information and options. IMPORTANT: You may need to close and restart your shell after running 'conda init'

To solve the error "CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'":

Open your terminal and run the following command. (Open Git Bash if you are on Windows)

shell
source ~/anaconda3/etc/profile.d/conda.sh conda activate my_env

conda source environment

Make sure to replace my_env with the name of your environment.

If your path to Anaconda or miniconda is different than ~/anaconda3, the command might fail.

Use the following command to get your path to Anaconda.

shell
conda info | grep -i 'base environment' conda info --base
Replace ~/anaconda3/ with the path to your Anaconda or miniconda installation.

get path to anaconda installation

For example, the path for me is /home/borislav/anaconda3, so I would issue the following commands.

shell
source /home/borislav/anaconda3/etc/profile.d/conda.sh conda activate my_env

conda activate environment

Make sure to update your path based on the output of the conda info --base command and specify the correct environment name when issuing the conda activate command.

If you are on Windows and the error persists, search for "Anaconda Prompt", open the application and issue the commands in Anaconda Prompt.

If the error persists, try to issue the following commands.

shell
eval "$(conda shell.bash hook)" conda activate my_env

conda activate environment alternative

Make sure to specify the correct environment name.

You can use the conda env list command to list your conda environments.

shell
conda env list

conda list environments

If you are in a script, you can set the CONDA_BASE environment variable to the output of the conda info --base command.

shell
CONDA_BASE=$(conda info --base)

set conda base environment variable

Note that if you issue the conda init command, you must restart your shell.

# Initializing your shell and activating your environment

Make sure to run the following commands in Git Bash if you are on Windows.

If none of the suggestions helped, try to issue the following commands.

  1. The following command activates your base environment.
shell
source ~/anaconda3/bin/activate source ~/miniconda3/bin/activate

conda activate base environment

  1. Check what type of shell you have.
shell
ps -p $$

check what type of shell you have

  1. Based on the output of the ps -p $$ command, initialize conda for your specific shell type.
shell
conda init <your-shell-type>

For example, if your shell type is bash, you would run the following command.

shell
conda init bash

My shell type is zsh, so I ran the conda init zsh command.

shell
conda init zsh

conda initialize shell type

Some of the supported shells for the conda init command are:

  • bash
  • cmd.exe
  • fish
  • tcsh
  • xonsh
  • zsh
  • powershell
  1. Restart your terminal window after running the conda init your_shell command.

Important: You need to close and restart your shell after running the conda init command.

  1. After you have closed and reopened your terminal, run the conda actiavte command.
shell
# 👇️ Activate base conda activate # 👇️ Or activate a specific environment conda activate my_env

Make sure to replace my_env with the name of your conda environment.

# Using eval to solve the error

If the error persists, try to use the eval command before running the conda activate command.

shell
eval "$(conda shell.bash hook)" conda activate my_env

using eval with conda

Make sure to replace my_env with the name of your environment.

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.