How to create a conda environment shortcut on Windows
Question:
With Anaconda installed I got a anaconda base
shortcut on Windows startmanu. To open the virtualenv I created (e.g., myenv
), I have to click the anaconda base
and type in activate myenv
in the opened cmd window.
How can I create a shortcut to get to myenv
with one-click, without open-and-typing like the above?
I’ve tried to create a copy of the base shortcut and change its command property i.e., %windir%System32cmd.exe "/K" C:Programsanaconda3Scriptsactivate.bat C:Programsanaconda3envsmyenv
. It does open the myenv cmdline, but seemed lost some buildin command,like conda
.
I guess I need a little bit help on Windows bat skills.
Answers:
The following works for me. The only change is that the parameter to activate.bat
is simply the env name (not the full path) as you would normally type it after an activate command. Your quotes were fine, BTW. For instance:
%windir%system32cmd.exe "/K" C:ProgramDataAnaconda3Scriptsactivate.bat myenv
You can get around this by installing the conda
package into the environment that you want to activate.
From an Anaconda Prompt (from where conda is already accessible):
conda install -n myenv conda
Then you can create a windows shortcut with target %windir%system32cmd.exe "/K" C:applAnaconda3Scriptsactivate.bat myenv
This is suboptimal as it pollutes your environment with the conda
dependencies, and I wouldn’t recommend it.
The other alternative is to add the C:Anaconda3Scripts
directory to the PATH
environment variable.
putting the comments above together in a simple batch script works flawlessly:
@echo off
set PATH=%PATH%;C:ProgramDataAnaconda3Scripts
%windir%system32cmd.exe "/K" C:ProgramDataAnaconda3Scriptsactivate.bat <env-name>
Mine automatically created a shortcut for Spyder with this format:
C:Anaconda3pythonw.exe C:Anaconda3cwp.py C:Anaconda3envspy36 C:Anaconda3envspy36pythonw.exe C:Anaconda3envspy36Scriptsspyder-script.py
Before creating new environment you can specify:
conda config --set shortcuts true
After that, you can see shortcuts for your new environment.
I use ConEmu
terminal, with traditional cmd.exe
shell. Here’s what my shortcut to MiniConda3
looks like:
C:Usersnmz787Downloadsconemu_22_08_07ConEmu64.exe -run {Shells::cmd} & C:Usersnmz787Miniconda3condabinconda.bat activate
With Anaconda installed I got a anaconda base
shortcut on Windows startmanu. To open the virtualenv I created (e.g., myenv
), I have to click the anaconda base
and type in activate myenv
in the opened cmd window.
How can I create a shortcut to get to myenv
with one-click, without open-and-typing like the above?
I’ve tried to create a copy of the base shortcut and change its command property i.e., %windir%System32cmd.exe "/K" C:Programsanaconda3Scriptsactivate.bat C:Programsanaconda3envsmyenv
. It does open the myenv cmdline, but seemed lost some buildin command,like conda
.
I guess I need a little bit help on Windows bat skills.
The following works for me. The only change is that the parameter to activate.bat
is simply the env name (not the full path) as you would normally type it after an activate command. Your quotes were fine, BTW. For instance:
%windir%system32cmd.exe "/K" C:ProgramDataAnaconda3Scriptsactivate.bat myenv
You can get around this by installing the conda
package into the environment that you want to activate.
From an Anaconda Prompt (from where conda is already accessible):
conda install -n myenv conda
Then you can create a windows shortcut with target %windir%system32cmd.exe "/K" C:applAnaconda3Scriptsactivate.bat myenv
This is suboptimal as it pollutes your environment with the conda
dependencies, and I wouldn’t recommend it.
The other alternative is to add the C:Anaconda3Scripts
directory to the PATH
environment variable.
putting the comments above together in a simple batch script works flawlessly:
@echo off
set PATH=%PATH%;C:ProgramDataAnaconda3Scripts
%windir%system32cmd.exe "/K" C:ProgramDataAnaconda3Scriptsactivate.bat <env-name>
Mine automatically created a shortcut for Spyder with this format:
C:Anaconda3pythonw.exe C:Anaconda3cwp.py C:Anaconda3envspy36 C:Anaconda3envspy36pythonw.exe C:Anaconda3envspy36Scriptsspyder-script.py
Before creating new environment you can specify:
conda config --set shortcuts true
After that, you can see shortcuts for your new environment.
I use ConEmu
terminal, with traditional cmd.exe
shell. Here’s what my shortcut to MiniConda3
looks like:
C:Usersnmz787Downloadsconemu_22_08_07ConEmu64.exe -run {Shells::cmd} & C:Usersnmz787Miniconda3condabinconda.bat activate