Conda not activate in Power Shell

一个人想着一个人 提交于 2020-12-29 12:58:17

问题


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>

回答1:


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.



来源:https://stackoverflow.com/questions/62082873/conda-not-activate-in-power-shell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!