'Python is in a Conda environment, but it has not been activated in a Windows virtual environment
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.
Solution 1:[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:[2]
Where myenv
is "your env name",
Try this:
conda activate myenv
conda install pip
This should solve the issue.
Solution 3:[3]
You have to activate your Conda environment after activating your environment of Flask.
So that you will have two virtual environments as shown here:
$(virtualenv) (env) C:\Users\Public\Projects\FlaskInt>python
Solution 4:[4]
I met a similar problem,
Python 3.7.6 (default, Jan 8 2020, 20:23:39) [MSC v.1916 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
Type "help", "copyright", "credits" or "license" for more information.
Failed calling sys.__interactivehook__
Traceback (most recent call last):
File "D:\anaconda\content\lib\site.py", line 439, in register_readline
readline.read_history_file(history)
File "D:\anaconda\content\lib\site-packages\pyreadline\rlmain.py", line 165, in read_history_file
self.mode._history.read_history_file(filename)
File "D:\anaconda\content\lib\site-packages\pyreadline\lineeditor\history.py", line 82, in read_history_file
for line in open(filename, 'r'):
UnicodeDecodeError: 'gbk' codec can't decode byte 0xae in position 1985: illegal multibyte sequence
But I solved the problem by replacing "r" with "rb" in line 82.
Solution 5:[5]
If you have anaconda, run the following from anaconda prompt:
conda config --set auto_activate_base true
Solution 6:[6]
I solved this problem by installing the python in the specific environment after activating it
conda install python
pip install python
with specific version
pip/conda install python==3.8
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Peter Mortensen |
Solution 2 | SherylHohman |
Solution 3 | Peter Mortensen |
Solution 4 | Peter Mortensen |
Solution 5 | shahar_m |
Solution 6 | Saran Zeb |