-
Notifications
You must be signed in to change notification settings - Fork 370
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mamba activate doesn't work in Powershell #1717
Comments
Mamba documentation ( https://mamba.readthedocs.io/en/latest/user_guide/mamba.html ) says:
|
Yes I did use conda for activating and deactivating for a long time, but I believe this is still a bug. mamba activate does work in Windows command prompt and on Linux/Mac terminals. As I also mentioned typing mamba activate gives no error in PowerShell, it just doesn't activate the environment - but the old behaviour if you typed mamba activate was to give an error prompt telling the user to use conda activate and it doesn't do that in PowerShell. The manual and mambas current behaviour appear inconsistent as even mamba prompts the user to "mamba activate" a new environment when you create one. |
I can confirm this issue.
|
Agree -- the fact that it silently fails when you try "mamba activate" in PowerShell is probably the biggest issue (besides just not changing the environment from |
Would anyone volunteer to make a fix PR? Or just a sketch of what places in the code need to be changed. |
@jonashaag Here's a crack at what I found based on my Windows Mambaforge installation: Versions: 1. Need a PowerShell-specific shortcutWhereas "Mambaforge Prompt" contains: "Mambaforge PowerShell Prompt" should be something like: (This was adapted from the PowerShell Prompt shortcut that Miniconda creates) 2a. Need to adapt "shell\condabin\conda-hook.ps1"Perhaps need to create "shell\condabin\mamba-hook.ps1" My "conda-hook.ps1" contains:
Presumably would want to augment with 2b. Need to adapt "shell\condabin\Conda.psm1"Perhaps need to create "shell\condabin\Mamba.ps1" Conda.psm1 gets referenced by conda-hook.ps1, and it is a ~300 line file It looks like a couple key places are:
I don't have time to experiment right now, but I might do some more investigating when I have a chance. Cheers, |
Confirm this issue. |
I confirmed that my recommendations do work! ( To summarize changes:
I will try to take a look at where in the codebase these new files would need to be created. I am not sure how "mirroring" conda files is dealt with in mamba (i.e. how to handle if Conda.psm1 changes in the future?), and furthermore whether mambaforge itself would need modified to create the shortcut with an install? Regardless, you can make these changes to your local install (at your own risk) -M |
And for good measure, in step 3 above, it also works with PowerShell 7 if you change the complete powershell.exe path at the beginning to (assuming you have 7 installed) |
Last nickel: Tab completion (as defined in Conda.psm1) will require further mods to Mamba.psm1 to match the Recommend inspecting Conda.psm1 to see where this could be added for mamba if someone gets to it before me |
Related issues I found that this fix might close or chip away at. I won't be able to implement my fix in the codebase anytime soon. CC: @wolfv @jonashaag |
I wish it wasn't the case that this is recommended ( / I wish it was the case that I often find myself accidentally typing |
Just my two cents: don't you need to explicitly say |
I found a way to avoid creating a shortcut and let the default powershell terminal open as if it would have been open with it.
Then add:
In Powershell, You can also repeat the steps for Windows Powershell by creating\modifying |
I had the same "silence" problem with
In this case, the conda init block in After I move the |
Managed to get tab autocompletion working: To add repoquery to autocomplete, in the above function I also aded a secion to my EDIT: |
It's been a while(a few years) since Window's default terminal has changed from CMD to Powershell. Shouldn't |
It would indeed be nice and helpful to have transparent PowerShell support for mamba and miniforge. The current miniforge3 installer for Windows only creates a 'CMD'-type prompt in the menu, without support for PowerShell. I was creating a fresh install of miniforge3 for use with mamba, migrating from a previous miniconda3 install. The latter does have a PowerShell prompt, and I was expecting miniforge to have a PS prompt too and work transparently with mamba as advertised. |
using mamba/1.5.3 conda/23.10.0: I tried both creating a shortcut and editing profile workarounds provided by @Alessandro201 but they did not work for me. Notes that may help someone in future:
repeatable test case:
|
As mambaforge has been deprecated in favour of miniforge, and there is a hint in the readme that mambaforge-related reports will be closed, it might be worthwhile to redo this repro with a miniforge installer. It probably won't make a difference, I guess, but will help avoid procedural issues getting in the way 😝 |
I use miniforge, and indeed it does not make a difference. The missing PowerShell support is probably more a miniforge issue than a pure mamba issue. I am just a simple scientific Python user, and look for simple installation procedures that I can easily share with colleagues and students, so that everyone has access to the Condaforge packages. I understand that the latest versions of conda (and the latest versions of the Anaconda and Miniconda distributions) now use the mamba solver internally by default, probably being as fast and efficient as mamba itself for installing packages. It may therefore be worth trying just installing Miniconda (which does have Powershell support) and setting the default channel to Condaforge. In any case, I appreciate all your efforts to keep this continuously evolving software ecosystem working. It does help us a great deal with our research work. Many thanks for that. |
Can confirm here that for Miniforge, |
I'm having the same issue with the latest Miniforge version. |
I'm having the same issue with the latest Miniforge. |
In case you also want to add conda/mamba to powershell profile, but instead of using the built-in # alternative conda activation method (https://github.com/conda/conda/issues/11648#issuecomment-1541546403)
# mamba activation (https://github.com/mamba-org/mamba/issues/1717#issuecomment-1292845827)
$Env:CONDA_EXE = "C:\Users\YOURUSENAME\scoop\apps\miniconda3\current\Scripts\conda.exe"
$ENV:MAMBA_EXE = "C:\Users\YOURUSENAME\scoop\apps\miniconda3\current\Scripts\mamba.exe" # for mamba
$Env:_CE_M = ""
$Env:_CE_CONDA = ""
$Env:_CONDA_ROOT = "C:\Users\YOURUSENAME\scoop\apps\miniconda3\current"
$Env:_CONDA_EXE = "C:\Users\YOURUSENAME\scoop\apps\miniconda3\current\Scripts\conda.exe"
$CondaModuleArgs = @{ChangePs1 = $False}
Import-Module "$Env:_CONDA_ROOT\shell\condabin\Conda.psm1" -ArgumentList $CondaModuleArgs
Import-Module "$Env:_CONDA_ROOT\shell\condabin\Mamba.psm1" -ArgumentList $CondaModuleArgs # for mamba
Remove-Variable CondaModuleArgs the above section sort of hooks conda to powershell, but instead of using the built-in |
Always use the "conda" command, it will be automatically converted when executed. Need Usage
# use command conda to call mamba or conda
Set-Alias -name conda -value CondaOrMamba
function CondaOrMamba {
param(
[Parameter(Position = 0, Mandatory = $true)]
[string]$Command,
[Parameter(ValueFromRemainingArguments = $true)]
[string[]]$Args
)
# list of mamba supported commands
$mambaCommands = @("install", "create", "list", "search", "run", "info", "clean", "remove", "update", "repoquery")
# check if the command is in the list of mamba commands
if ($mambaCommands.Contains($Command)) {
& mamba $Command @Args
} else {
# use Invoke-Conda instead of conda
& Invoke-Conda $Command @Args
}
}
|
The latest version of minifoge 24.3.0 still suffers from this problem |
got the same problem too |
还未解决吗,不能使用 |
same issue |
wasted 30 minutes on this. implementing one of the workarounds. |
As of 2.0, I can use micromamba activate in powershell on Linux after:
|
We can also observe that this has been fixed on Windows 11 when using micromamba 2.0.4. Can someone confirm or infirm? |
As mentioned by @alex180500 on conda-forge/miniforge#516 (comment), using:
from the miniforge prompt set up |
Closing as fixed. |
I'm using mamba 0.23.3 on Windows 11 and noticed the mamba activate command doesn't work in Powershell (original or Powershell Core).
Normally I use the old Windows command prompt terminal (Miniforge prompt / Anaconda (Miniconda 3) terminal) but I wanted to use Powershell again. I launched my base conda environment in Powershell using the Anaconda Powershell Prompt (miniconda3) shortcut - implemented using the powershell_shortcut package.
I can still use conda to activate environments in Powershell but trying to use mamba activate has no effect and also gives no error. See screenshot below:
The text was updated successfully, but these errors were encountered: