menuinst
menuinst copied to clipboard
Easily creating shortcuts with the powershell_shortcut_miniconda and console_shortcut_miniconda packages, and can this be replicated with menuinst ?
Checklist
- [X] I added a descriptive title
- [X] I searched open reports and couldn't find a duplicate
What happened?
My problem
I have installed miniconda3 on Windows 10 (and on several Linux platforms) and thoroughly documented all the steps, so that our students can understand and replicate this, and can then create their own clean environments, without altering the base environment
After installing miniconda3 on Windows, you end up with a Miniconda3 (64-bit)
Windows menu, a shortcut to open an Anaconda Powershell Prompt
and one to open an Anaconda Prompt
, both with the base
environment activated
I had no idea where these convenient shortcuts were coming from, and I wanted to find a clean way to create direct shortcuts to new (non-base
) environments, on Windows. So that students can directly start a specific environment, without having to type conda activate env
). You've got to make things easy for new users, if you want to get them past notebooks...
What I have tried
I have relatively quickly found out about menuinst
on Google and played a bit (a lot, too much, actually) with in order to understand more about the json config files. I figured that generating and distributing a good json config file to our students would do the trick
Unfortunately, I have read and re-read the menuinst documentation (and filled some issues along the way) and got the impression I was running in circles and not getting anywhere near my easy environment initialization goal.
The documentation is not very clear/detailed about using non-base environments. The closest thing I found was Specifying different shortcut names for base and non-base environments. But this seemed like a very convoluted way to get thins done, and I did not really get it working. Maybe I'll fill an issue about that. For selecting a non based environment, I was more expecting something like : use a parameter in the json file to specify the environment name, and then create the shortcuts by calling menuinst in the base environment
I also tried to do some reverse engineering by comparing the content of my json files to the generated .lnk
and .bat
files but this only got me some severe headaches. I'm mostly a Linux user and I know next to nothing about .bat
files and powershell syntax
What seems to work (without using menuinst explicitly...)
I tried to understand where the Windows shortcuts (to base
) that appeared when I installed miniconda3 were coming from, and I eventually found out that they were provided by the powershell_shortcut_miniconda
and console_shortcut_miniconda
packages bundled with miniconda3 !
It is actually trivial to install or uninstall either the powershell
or the console
shortcuts (or both) by just installing or removing the powershell_shortcut_miniconda
and console_shortcut_miniconda
packages
In the example below, I easily create a Windows menu shortcut to my spyder_test
environment, from the base
environment
(base) PS C:\Users\jypeter\menuinst_test> conda list menuinst
# packages in environment at C:\Utils\miniconda3_2024-03:
#
# Name Version Build Channel
menuinst 2.1.1 py312h275cf98_0 conda-forge
(base) PS C:\Users\jypeter\menuinst_test> conda install -n spyder_test powershell_shortcut_miniconda
Channels:
- conda-forge
- defaults
Platform: win-64
Collecting package metadata (repodata.json): done
Solving environment: done
## Package Plan ##
environment location: C:\Utils\miniconda3_2024-03\envs\spyder_test
added / updated specs:
- powershell_shortcut_miniconda
The following NEW packages will be INSTALLED:
powershell_shortc~ pkgs/main/win-64::powershell_shortcut_miniconda-0.0.1-haa95532_2
Proceed ([y]/n)? y
After testing the Windows menu shortcut, I can also easily remove the shortcut, still from the base
environment
(base) PS C:\Users\jypeter\menuinst_test> conda remove -n spyder_test powershell_shortcut_miniconda Channels:
[...]
The following packages will be REMOVED:
powershell_shortcut_miniconda-0.0.1-haa95532_2
Proceed ([y]/n)? y
I can also create and remove the shortcuts directly from the non-base
environment. Note that menuinst is not installed in that environment, but I guess that if conda can be called from this non-base
environment, it can also use menuinst from the base environment
(base) PS C:\Users\jypeter\menuinst_test> conda activate spyder_test
(spyder_test) PS C:\Users\jypeter\menuinst_test> conda list menuinst
# packages in environment at C:\Utils\miniconda3_2024-03\envs\spyder_test:
#
# Name Version Build Channel
(spyder_test) PS C:\Users\jypeter\menuinst_test> where.exe conda
C:\Utils\miniconda3_2024-03\condabin\conda.bat
(spyder_test) PS C:\Users\jypeter\menuinst_test> where.exe python
C:\Utils\miniconda3_2024-03\envs\spyder_test\python.exe
C:\Users\jypeter\AppData\Local\Microsoft\WindowsApps\python.exe
(spyder_test) PS C:\Users\jypeter\menuinst_test> conda install powershell_shortcut_miniconda
[...]
## Package Plan ##
environment location: C:\Utils\miniconda3_2024-03\envs\spyder_test
added / updated specs:
- powershell_shortcut_miniconda
The following NEW packages will be INSTALLED:
powershell_shortc~ pkgs/main/win-64::powershell_shortcut_miniconda-0.0.1-haa95532_2
Proceed ([y]/n)? y
[...]
(spyder_test) PS C:\Users\jypeter\menuinst_test> conda remove powershell_shortcut_miniconda
Channels:
- conda-forge
- defaults
Platform: win-64
Collecting package metadata (repodata.json): done
Solving environment: done
## Package Plan ##
environment location: C:\Utils\miniconda3_2024-03\envs\spyder_test
removed specs:
- powershell_shortcut_miniconda
The following packages will be REMOVED:
powershell_shortcut_miniconda-0.0.1-haa95532_2
Proceed ([y]/n)? y
How do 'powershell_shortcut_miniconda' and 'console_shortcut_miniconda' work ?
I'm glad I found an easy solution to my initial problem, but this raised other questions
I have found the following json files in the packages
C:\Utils\miniconda3_2024-03\pkgs\console_shortcut_miniconda-0.1.1-haa95532_2\Menu\console_shortcut.json
{
"menu_name": "Miniconda${PY_VER} ${PLATFORM}",
"menu_items":
[
{
"name": "Anaconda Prompt (${DISTRIBUTION_NAME})",
"system": "%windir%\\System32\\cmd.exe",
"scriptarguments": ["/K", "${ROOT_PREFIX}\\Scripts\\activate.bat", "${PREFIX}"],
"icon": "${MENU_DIR}/anaconda_console.ico"
}
]
}
C:\Utils\miniconda3_2024-03\pkgs\powershell_shortcut_miniconda-0.0.1-haa95532_2\Menu\powershell_shortcut.json
{
"menu_name": "Miniconda${PY_VER} ${PLATFORM}",
"menu_items":
[
{
"name": "Anaconda Powershell Prompt (${DISTRIBUTION_NAME})",
"system": "%windir%\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
"scriptarguments": ["-ExecutionPolicy", "ByPass", "-NoExit", "-Command", "& '${ROOT_PREFIX}\\shell\\condabin\\conda-hook.ps1' ; conda activate '${PREFIX}' "],
"icon": "${MENU_DIR}/anaconda_powershell_console.ico"
}
]
}
My new questions:
- Is this the old menuinst syntax?
- Are these packages installed by the new menuinst, even if they use the old syntax, or is conda calling another package ?
- Can you get the same result using the new syntax
- Where are the variables definition coming from?
${PY_VER}
is giving a better result (3
) than the{{ PY_VER }}
placeholder (N. A.
). See #235
My other requirement: Windows Terminal profiles
I would also like to easily create Windows Terminal profiles that would open a Windows terminal using the base
or a non-base
environment.
I understand that this can theoretically be achieved with the terminal_profile
option, and has been covered by #196 . Can somebody provide a detailed example for both cases (base
and non-base
). I have already spent way tp much time on this and I need to move on to creating actual complex (and non-base
!) environments
There are lots of online tutorials to do this, but they may be obsolete or not safe. And I'd like a clean way to do this (distributing a json file would be nice)
- https://arturomoncadatorres.com/incorporating-anaconda-prompt-windows-terminal/
- https://www.pugetsystems.com/labs/hpc/note-adding-anaconda-powershell-to-windows-terminal-1907/
- https://stackoverflow.com/questions/70639974/setting-up-an-anaconda-powershell-prompt-profile-in-windows-terminal
- https://stackoverflow.com/questions/76530371/how-to-configure-an-anaconda-shell-on-windows-terminal-but-with-powershell-7
- ...
Thanks!
Additional Context
No response