John Wang
John Wang

Reputation: 4692

How to create a conda environment shortcut on Windows

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%\System32\cmd.exe "/K" C:\Programs\anaconda3\Scripts\activate.bat C:\Programs\anaconda3\envs\myenv. 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.

Upvotes: 11

Views: 16730

Answers (7)

Garrick Peschke
Garrick Peschke

Reputation: 21

For miniconda it's:

@echo off    
set PATH=%PATH%;C:\ProgramData\miniconda3\Scripts
%windir%\system32\cmd.exe "/K" C:\ProgramData\miniconda3\Scripts\activate.bat video

Was gonna leave it as a comment on Jonathan's, but I'm new ><.

Upvotes: 2

nmz787
nmz787

Reputation: 2180

I use ConEmu terminal, with traditional cmd.exe shell. Here's what my shortcut to MiniConda3 looks like: C:\Users\nmz787\Downloads\conemu_22_08_07\ConEmu64.exe -run {Shells::cmd} & C:\Users\nmz787\Miniconda3\condabin\conda.bat activate

Upvotes: 0

illuminato
illuminato

Reputation: 1257

Before creating new environment you can specify:

conda config --set shortcuts true

After that, you can see shortcuts for your new environment.

Upvotes: 1

endolith
endolith

Reputation: 26853

Mine automatically created a shortcut for Spyder with this format:

C:\Anaconda3\pythonw.exe C:\Anaconda3\cwp.py C:\Anaconda3\envs\py36 C:\Anaconda3\envs\py36\pythonw.exe C:\Anaconda3\envs\py36\Scripts\spyder-script.py

Upvotes: 1

Jonathan
Jonathan

Reputation: 104

putting the comments above together in a simple batch script works flawlessly:

@echo off    
set PATH=%PATH%;C:\ProgramData\Anaconda3\Scripts
%windir%\system32\cmd.exe "/K" C:\ProgramData\Anaconda3\Scripts\activate.bat <env-name>

Upvotes: 8

RubenLaguna
RubenLaguna

Reputation: 24846

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%\system32\cmd.exe "/K" C:\appl\Anaconda3\Scripts\activate.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:\Anaconda3\Scripts directory to the PATH environment variable.

Upvotes: -2

Gronk
Gronk

Reputation: 159

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%\system32\cmd.exe "/K" C:\ProgramData\Anaconda3\Scripts\activate.bat myenv

Upvotes: 3

Related Questions