Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conda not activated in Power Shell

I have already install anaconda on my Windows 10 laptop. I'm trying to activate the Python environment named pyenv.

First, I check the conda env list in my laptop, this is the output on the power shell:

PS C:\Users\User> conda env list
# conda environments:
#
base                  *  C:\Users\User\Anaconda3
pyenv                    C:\Users\User\Anaconda3\envs\pyenv

Then I activate pyenv:

PS C:\Users\User> conda activate pyenv

But I check again, it still activates base environment:

PS C:\Users\User> conda env list
# conda environments:
#
base                  *  C:\Users\User\Anaconda3
pyenv                    C:\Users\User\Anaconda3\envs\pyenv

When I use the Anaconda prompt, it works normally:

(base) C:\Users\User>conda activate pyenv

(pyenv) C:\Users\User>

Does anyone know why it causes this problem and how to fix this?

Update:

Running conda init powershell:

PS C:\Users\User> conda init powershell
no change     C:\Users\User\Anaconda3\Scripts\conda.exe
no change     C:\Users\User\Anaconda3\Scripts\conda-script.py
no change     C:\Users\User\Anaconda3\Scripts\conda-env-script.py
no change     C:\Users\User\Anaconda3\condabin\conda.bat
no change     C:\Users\User\Anaconda3\Library\bin\conda.bat
no change     C:\Users\User\Anaconda3\condabin\_conda_activate.bat
no change     C:\Users\User\Anaconda3\condabin\rename_tmp.bat
no change     C:\Users\User\Anaconda3\condabin\conda_hook.bat
no change     C:\Users\User\Anaconda3\Scripts\activate.bat
no change     C:\Users\User\Anaconda3\condabin\activate.bat
no change     C:\Users\User\Anaconda3\condabin\deactivate.bat
modified      C:\Users\User\Anaconda3\etc\profile.d\conda.sh
modified      C:\Users\User\Anaconda3\etc\fish\conf.d\conda.fish
no change     C:\Users\User\Anaconda3\shell\condabin\Conda.psm1
modified      C:\Users\User\Anaconda3\shell\condabin\conda-hook.ps1
no change     C:\Users\User\Anaconda3\Lib\site-packages\xontrib\conda.xsh
modified      C:\Users\User\Anaconda3\etc\profile.d\conda.csh
modified      C:\Users\User\Documents\WindowsPowerShell\profile.ps1

Update 2: It works when using CMD:

C:\Users\User>conda activate pyenv

(pyenv) C:\Users\User>
like image 392
huy Avatar asked May 29 '20 09:05

huy


People also ask

Is it possible to activate Conda environments with PowerShell?

The python extension officially does not support powershell for activating conda environments “Note: conda environments cannot be automatically activated in the integrated terminal if PowerShell is set as the integrated shell. See Integrated terminal - Configuration for how to change the shell.” - Using python environments in VSCode

How do I initialize my shell in conda?

To initialize your shell, run $ conda init <SHELL_NAME> Currently supported shells are: - bash - fish - tcsh - xonsh - zsh - powershell See 'conda init --help' for more information and options. IMPORTANT: You may need to close and restart your shell after running 'conda init'.

How do I run Anaconda from a PowerShell prompt?

For those who are still stuck-> Go to windows search -> Search for "Anaconda Powershell Prompt" -> With the opened Powershell, prompt type conda init powershell and hit enter-> type conda and hit enter in the same poweshell prompt to check if it worked. Note: I used miniconda and the flow works.

Does Conda init work with Anaconda installation?

So I mass tested Anaconda installation and conda init in a class of approx. twenty students and everything works fine as long as one runs in the elevated powershell. Otherwise one gets the aforementionend permission error.


Video Answer


1 Answers

After a while, my Powershell appear this error when I open it.

. : File C:\Users\User\Documents\WindowsPowerShell\profile.ps1 cannot be loaded because running scripts is
    disabled on this system. For more information, see about_Execution_Policies at
    https:/go.microsoft.com/fwlink/?LinkID=135170.
    At line:1 char:3
    + . 'C:\Users\BinoyGhosh\Documents\WindowsPowerShell\profile.ps1'
    +   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : SecurityError: (:) [], PSSecurityException
        + FullyQualifiedErrorId : UnauthorizedAccess

Then I found this solution.

  • Run Powershell as Administrator
  • Run this line set-executionpolicy remotesigned
  • Close the terminal

Then it works.

enter image description here

like image 87
huy Avatar answered Sep 29 '22 09:09

huy