Reputation: 321
Running Bash in Cmder on Windows 10. I am trying to activate a new virtual environment but keep getting told to run 'conda init' before 'conda activate'. I've tried running conda init but I keep getting prompted to do it again.
I'm guessing that it might have something to do with how I installed miniconda. I followed the instructions here which specifically states:
"On Windows, you’ll be asked if you want to add Miniconda to your PATH variable. Although it recommends that you do not do this, DO add it to your PATH. This will be important when we change how our command line works."
But when I read up on the conda documentation here it states:
"When installing Anaconda, you have the option to “Add Anaconda to my PATH environment variable.” This is not recommended because it appends Anaconda to PATH. When the installer appends to PATH, it does not call the activation scripts."
I'm guessing that this is the issue but I don't know of a work around (if one is needed). I am very new to coding.
Actions and Errors below:
I create my environment:
conda create --name test_env
The environment is created and then I am told to:
# To activate this environment, use
#
# $ conda activate test_env
#
# To deactivate an active environment, use
#
# $ conda deactivate
I attempt to activate:
conda activate test_env
Ouput
CondaError: Run 'conda init' before 'conda activate'
I run 'conda init':
λ conda init
no change C:\Users\Username\miniconda3\Scripts\conda.exe
no change C:\Users\Username\miniconda3\Scripts\conda-env.exe
no change C:\Users\Username\miniconda3\Scripts\conda-script.py
no change C:\Users\Username\miniconda3\Scripts\conda-env-script.py
no change C:\Users\Username\miniconda3\condabin\conda.bat
no change C:\Users\Username\miniconda3\Library\bin\conda.bat
no change C:\Users\Username\miniconda3\condabin\_conda_activate.bat
no change C:\Users\Username\miniconda3\condabin\rename_tmp.bat
no change C:\Users\Username\miniconda3\condabin\conda_auto_activate.bat
no change C:\Users\Username\miniconda3\condabin\conda_hook.bat
no change C:\Users\Username\miniconda3\Scripts\activate.bat
no change C:\Users\Username\miniconda3\condabin\activate.bat
no change C:\Users\Username\miniconda3\condabin\deactivate.bat
modified C:\Users\Username\miniconda3\Scripts\activate
modified C:\Users\Username\miniconda3\Scripts\deactivate
modified C:\Users\Username\miniconda3\etc\profile.d\conda.sh
modified C:\Users\Username\miniconda3\etc\fish\conf.d\conda.fish
no change C:\Users\Username\miniconda3\shell\condabin\Conda.psm1
modified C:\Users\Username\miniconda3\shell\condabin\conda-hook.ps1
no change C:\Users\Username\miniconda3\Lib\site-packages\xontrib\conda.xsh
modified C:\Users\Username\miniconda3\etc\profile.d\conda.csh
no change C:\Users\Username\Documents\WindowsPowerShell\profile.ps1
modified HKEY_CURRENT_USER\Software\Microsoft\Command Processor\AutoRun
==> For changes to take effect, close and re-open your current shell. <==
I exit out of the shell, reopen and run:
conda activate test_env
And again get
CondaError: Run 'conda init' before 'conda activate'
I have tried executing these steps in various orders and closing the shell vs not but I am stuck in the same loop.
Upvotes: 32
Views: 80002
Reputation: 91
conda init
needs the shell name sometimes
If using zsh, run:
conda init zsh
Exit out of the shell, reopen and run:
conda activate test_env
Upvotes: 9
Reputation: 1
close powershell, then use cmd to run your code, which makes sense to you. hope ,help you
Upvotes: 0
Reputation: 422
For me on windows, it worked this:
activate test_env
without calling the conda first.
Upvotes: 0
Reputation: 11
I also had similar error, but its turn out because i use powershell instead of cmd on vscode when i type the conda activate name
Upvotes: 1
Reputation: 21
Was encountering the same issue. This worked for me.
source <path to conda>/bin/activate
.conda init <shell name>
.Where <path to conda>
is retrieved by the following steps:
conda info
.base environment
or conda location
. This is usually where Conda is
installed.Source: Should I add Anaconda to the macOS or Linux PATH? — Anaconda documentation
Upvotes: 2
Reputation: 913
First run:
source activate base # ( this would activate your conda base env )
and then
conda activate my_env # ( replace my_env with name of your new env )
Upvotes: 36
Reputation: 31
In windows , You should change your security policy. First, run powershell using Administrator. Then,
Set-ExecutionPolicy RemoteSigned
Then, input Y
Then, reopen your powershell, then you can use:
conda activate your_env
Upvotes: 3
Reputation: 1
This worked for me if you're using zsh
source activate base
conda activate venv
Upvotes: 0
Reputation: 196
For mac:
conda create --name test_env
conda init zsh
source ~/.zshrc
conda activate test_env
Upvotes: 2
Reputation: 1
I had the same issue when I was using the terminal of visual studio but I fixed it by using cmd >>> enviroment folder > conda activate env_name
Upvotes: 0
Reputation: 2262
Now in 2024, for people struggling with conda installation and env creation, when you install anaconda with homebrew like this:
brew install anaconda
// or
brew install --cask anaconda
if you are using default bash, you will need to run:
/opt/homebrew/anaconda3/bin/conda init
which will write necessary config in ~/.bash_profile
file.
/opt/homebrew/anaconda3/bin/conda init zsh
which will write necessary config in ~/.zshrc
file.
/usr/local/anaconda3/bin/conda
.Now conda is in the terminal. You can create your python environment like this(note I specified which version of python I want to use for this env, and openwebui
is the name of my env name):
conda create --name openwebui python=3.11
When you start a new terminal session, conda is using the base
env, when you cd
into the directory you want to use the openwebui
env, you run:
conda activate openwebui
brew install anaconda
and brew install --cask anaconda
both installs anaconda
and Anaconda Navigator on you Mac.
If you want manage python versions on your Mac, you may want to try:
Upvotes: 3
Reputation: 1
I just had the same issue but I fixed it with the following steps:
cd ~
source .bashrc
conda activate envname
Upvotes: 0
Reputation: 11
Start powershell as admin
Try one of the following methods:
Change Execution Policy Temporarily:
command: Set-ExecutionPolicy RemoteSigned -Scope Process
This command sets the execution policy to allow running locally created scripts. After running this command, try executing your script again.
Change Execution Policy Permanently:
For the current user:
Command: Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
For the entire system:
Command: Set-ExecutionPolicy RemoteSigned -Scope LocalMachine
After changing the execution policy, you should be able to run your script without encountering the error.
Upvotes: 1
Reputation: 46
To expand on the answers by wofy92 and acookie, the conda init --help
says:
usage: conda init ... [SHELLS ...]
SHELLS One or more shells to be initialized. If not given, the default value is 'bash' on unix and 'cmd.exe' & 'powershell' on Windows.
Not sure why it's not working to simply specify conda init
, but you can try conda init --all
to initialise all shells ('bash', 'cmd.exe', 'fish', 'powershell', 'tcsh', 'xonsh', 'zsh'
) or specify your specific shell, such as conda init bash
.
Upvotes: 0
Reputation: 519
In MacOS, i use conda init zsh
,and i get the following message. It works!
$ conda init zsh
no change /opt/anaconda3/condabin/conda
no change /opt/anaconda3/bin/conda
no change /opt/anaconda3/bin/conda-env
no change /opt/anaconda3/bin/activate
no change /opt/anaconda3/bin/deactivate
no change /opt/anaconda3/etc/profile.d/conda.sh
no change /opt/anaconda3/etc/fish/conf.d/conda.fish
no change /opt/anaconda3/shell/condabin/Conda.psm1
no change /opt/anaconda3/shell/condabin/conda-hook.ps1
no change /opt/anaconda3/lib/python3.11/site-packages/xontrib/conda.xsh
no change /opt/anaconda3/etc/profile.d/conda.csh
modified /Users/acookie/.zshrc
==> For changes to take effect, close and re-open your current shell. <==
Upvotes: 51