Search code examples
pythonvisual-studio-codeminiconda

I cannot activate my virtual environment from anaconda into vscode


I created a virtual environment in miniconda3

I then installed all the the packages I wanted to use for my project ( pip install snowflake snowpark-python streamlit)

Afterwards, I opended up VsCode and used the python interpreter and selected my virtual environment.

Afterwards when I try to run a command like "streamlit hello" it shows that the package was not installed.

However when I run the same command in my minicondaPrompt it works perfectly fine.

I then realized I had to activate the environment aswell in my vscode terminal. Here's where the problem occurs

I use the command stenv\Scripts\activate.bat and I get the error

stenv\Scripts\activate.bat : The module 'stenv' could not be loaded. For more information, run 'Import-Module stenv'. At line:1 char:1

  • stenv\Scripts\activate.bat
  •   + CategoryInfo          : ObjectNotFound: (stenv\Scripts\activate.bat:String) [], CommandNotFoundException       
      + FullyQualifiedErrorId : CouldNotAutoLoadModule
    

Solution

    1. Select the Conda environment interpreter in Selecting Interpreter panel.

      enter image description here

    2. The selected interpreter version will be displayed in the lower right corner

      enter image description here

    3. Without modifying this default setting, the new terminal will automatically activate the environment.

      "python.terminal.activateEnvironment": false
      

      enter image description here

    You don't have to use the command to operate at the terminal. It is more convenient to install Python extension and use it to execute the script.

    There are more information here: