profile
viewpoint

Ask questions'conda activate conda-environment' not working on Windows 10

Environment data

  • VS Code version: 1.33.1
  • Extension version (available under the Extensions sidebar): 2019.4.12954
  • OS and version: Windows 10
  • Python version (& distribution if applicable, e.g. Anaconda): Anaconda 4.5.11
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): conda

Expected behaviour

When a conda environment is selected as the Python interpreter and a Python script is run in terminal, the environment should be activated by the 'conda activate env-name' command and the script should be run in the environment.

Actual behaviour

The terminal shows a CommandNotFoundError:

CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'. If your shell is Bash or a Bourne variant, enable conda for the current user with

$ echo ". C:\Users\user\Anaconda3/etc/profile.d/conda.sh" >> ~/.bashrc

or, for all users, enable conda with

$ sudo ln -s C:\Users\user\Anaconda3/etc/profile.d/conda.sh /etc/profile.d/conda.sh

The options above will permanently enable the 'conda' command, but they do NOT put conda's base (root) environment on PATH. To do so, run

$ conda activate

in your terminal, or to put the base environment on PATH permanently, run

$ echo "conda activate" >> ~/.bashrc

Previous to conda 4.4, the recommended way to activate conda was to modify PATH in your ~/.bashrc file. You should manually remove the line that looks like

export PATH="C:\Users\user\Anaconda3/bin:$PATH"

^^^ The above line should NO LONGER be in your ~/.bashrc file! ^^^

The script is then executed by explicitly calling the full path to the conda environment: C:/Users/user/Anaconda3/envs/env-name/python.exe

The same error is obtained when I run 'conda activate env-name' in Command Prompt or in Windows PowerShell.

I can activate the environment by running 'activate env-name' in Command Prompt.

If I run 'activate env-name' in Windows PowerShell, I get an error:

activate : File C:\Users\user\Anaconda3\Scripts\activate.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:1

  • activate vscode
  •   + CategoryInfo          : SecurityError: (:) [], PSSecurityException
      + FullyQualifiedErrorId : UnauthorizedAccess
    

I get this same error if I run 'activate env-name' in the VS Code Terminal.

Steps to reproduce:

  1. Select a conda environment as the Python interpreter
  2. Execute a .py file by: right-click -> Run Python File in Terminal
microsoft/vscode-python

Answer questions fleimgruber

@DonJayamanne After conda init powershell from a PowerShell it works over here. Is this documented already? Would https://code.visualstudio.com/docs/editor/integrated-terminal#_configuration be a good place for this?

useful!
source:https://uonfu.com/
Github User Rank List