PSCondaEnvs icon indicating copy to clipboard operation
PSCondaEnvs copied to clipboard

Works to Activate, but Deactivate fails

Open raistael opened this issue 7 years ago • 10 comments

The process of trying to deactivate an env or activate a different one after activating the first one doesn't successfully complete. There are no errors that show up in the console, it just refuses to switch.

raistael avatar Apr 26 '17 18:04 raistael

I tried and works fine...

PS C:\WINDOWS\system32> activate p35

Activating environment "p35..."


[p35] PS C:\WINDOWS\system32> desactivate

Deactivating environment "p35..."


PS C:\WINDOWS\system32> activate p27

Activating environment "p27..."


[p27] PS C:\WINDOWS\system32> desactivate

Deactivating environment "p27..."

felansu avatar Apr 26 '17 18:04 felansu

@felansu it seems you have a different version of these scripts or have modified them yourself, as your console output uses the term "desactivate" whereas it should be "deactivate" followed by the environment name. Perhaps you will share your version of deactivate.ps1 so I can compare?

raistael avatar Apr 26 '17 18:04 raistael

@raistael [ . . . ] ¬.¬' rename to deactivate.ps1 . . . . its only an example because i renamed to desactivate... no diference...

felansu avatar Apr 26 '17 19:04 felansu

@felansu - Well, alright, but unaltered the script doesn't work for me. Perhaps I'm running a different PoSh environment than you, or a different OS

raistael avatar Apr 26 '17 19:04 raistael

@raistael i'm using windows 10x64

felansu avatar Apr 26 '17 19:04 felansu

@felansu as am I, but the Pro version

raistael avatar Apr 26 '17 19:04 raistael

I haven't used these in a long time but they should still work fine and have for a number of people. Try specifying the name and extension as "deactive.ps1 env" It might be that it's not getting prioritized over the default deactivate.bat.

I thought Anaconda was going a different direction and baking this functionality in but it seems like this is still used. If there's interest I'd like to update this to a proper Powershell module and publish it to the PS Gallery.

Liquidmantis avatar Apr 26 '17 20:04 Liquidmantis

@Liquidmantis - You appear to be right. For some reason, I assumed that since activate my_env worked as expected that deactivate my_env would work also. By adding the .ps1 to the end it seems to work just fine. I'll have to figure out how to have both .bat and .ps1 work in cooperation, as I still sometimes use cmd to get simpler things done or run old scripts.

And you're quite right. Supposedly this functionality was "implemented" with conda 4.3, but even then they said it was "inconsistent." I'm not entirely sure why they find it so difficult to implement such a trivial thing, especially given the newer bash-like behavior of PoSh, but I guess it's just not that high on their priorities list.

I would definitely like to see these files refined a bit and published on the PoSh Gallery, if you're willing to spend a little bit of time to do so. I'll be the first to download it, haha 😆

-- Edit -- As a side-note, the default behavior of the .bat activate my_env allows for selecting root as the environment, but yours checks for root in the envs folder and returns that it doesn't exist (because it doesn't), so if you improve on these and turn them into a proper module, that should probably be fixed

raistael avatar Apr 27 '17 02:04 raistael

I can explain why you have to type deactivate.ps1: when you conda create something it creates a folder in (on windows with anaconda 3) c:\programdata\anaconda3\ENVS<ENVNAME>\Scripts. And in that folder (which comes first when you run activate.ps1, that's why they're envs) there is already created a deactivate activate activate.bat and deactivate.bat, at least on my install. Not only COM but even PowerShell preferentially therefore selects deactivate.bat (which in context does nothing). So I dunno if there are "hooks" in conda create, but if you simply, e.g., conda create -n ENVNAME python=some.version and THEN type cp c:\programdata\anaconda3\scripts\deactivate.ps1 c:\progamdata\anaconda3\envs\ENVNAME\scripts, you'd be done. You could get around this by modifying the activate.ps1 and adding a line that basically says if there's no deactivate.ps1 in my env, copy it in there. Now, the people saying it works have modified some settings somewhere to avoid having to do this, but it's a good fix if you haven't.

(For example, in the block that has "Activating environment ..." just above the two blank Write-Host lines in activate.ps1, I typed: Copy-Item -Path "C:\ProgramData\Anaconda3\Scripts\deactivate.ps1" -Destination "C:\ProgramData\Anaconda3\envs$condaEnvName\Scripts"

And I probably should have used Copy-Item -Path "$anacondaInstallPath\Scripts\deactivate.ps1" -Destination "$env:ANACONDA_ENVS$condaEnvName\Scripts" to be more general.

dhpennell avatar Jun 29 '17 21:06 dhpennell

@dhpennell It worked, but I think you missed a backslash between envs and $condaEnvName in Copy-Item -Path "C:\ProgramData\Anaconda3\Scripts\deactivate.ps1" -Destination "C:\ProgramData\Anaconda3\envs$condaEnvName\Scripts" or ANACONDA_ENVS and $condaEnvName in Copy-Item -Path "$anacondaInstallPath\Scripts\deactivate.ps1" -Destination "$env:ANACONDA_ENVS$condaEnvName\Scripts"

willsunustc avatar Jul 11 '17 08:07 willsunustc