Python is in a Conda environment, but it has not been activated in a Windows virtual environment

45,890

Solution 1

The error message tells you that the Python interpreter from the Conda environment was found, but that conda activate <envname> has not been called. Did you put the bin/ directory of the Conda environment into the Windows search path? That would be wrong.

You're talking about virtualenvs. But Python virtual environments are something else than Conda environments. Maybe you mixed up the two concepts?

The Python interpreter from the Conda base environment does not complain about missing activation, because it's called by some of the conda subcommands and can work without an activated environment. Nevertheless, you should call conda activate base when working with that Conda environment, too.

Solution 2

Where myenv is "your env name",

Try this:

conda activate myenv

conda install pip

This should solve the issue.

Share:
45,890
Bill
Author by

Bill

Updated on February 20, 2022

Comments

  • Bill
    Bill about 2 years

    I created a Windows (10) Python virtual environment (env3.7.3). When I open a cmd window activated in the virtual environment, I get the following warning message when starting Python in the virtual environment:

    (env3.7.3) C:\Users\redex\OneDrive\Documents\Education\Machine Learning-Ng Python\Exercise7>python
    Python 3.7.3 (default, Apr 24 2019, 15:29:51) [MSC v.1915 64 bit (AMD64)] :: Anaconda, Inc. on win32
    Warning:
    This Python interpreter is in a conda environment, but the environment has
    not been activated.  Libraries may fail to load.  To activate this environment
    please see https://conda.io/activation
    

    This warning has been posted before in a different context, but it did not address my question. This warning appears only in the Python virtual environment, not the base Conda environment. This seems like a Windows or Anaconda environment variable issue, but I don't know enough to know! Anaconda was recently upgraded and it seemed fine before, so there may be a bug or setting issue.

  • Bill
    Bill almost 5 years
    Thanks for the reply. My intention is to create a Python virtual env, not a conda environment. The reason is related to a problem VS Code has with conda when invoking the debugger (see stackoverflow.com/questions/56475068/…) By creating a local python virtual environment, the debugger works properly.
  • Roland Weber
    Roland Weber almost 5 years
    @Bill If you want to work with Python virtual environments, then don't use conda at all. The two don't mix.
  • XYZ
    XYZ about 3 years
    where should I "Try this"? In the Windows cmd, conda : The term 'conda' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:1 + conda activate myenv
  • Peter Mortensen
    Peter Mortensen over 2 years
    Why does Flask enter the picture? Can you elaborate? What is the reason for the order rule?
  • Peter Mortensen
    Peter Mortensen over 2 years
    Line 82 of what? What is in line 82? Please respond by editing (changing) your answer, not here in comments (without "Edit:", "Update:", or similar - the answer should appear as if it was written today).