Search code examples
pythonpipconda

PEP 668 Error (Externally managed environment) within Conda


While trying to pip install packages, even though I am inside a Conda environment, I'm getting the familiar error:

error: externally-managed-environment

I would expect this if I'm using Python directly from the system prompt. But why do I get this even inside the Conda environment?


Solution

  • Ok, after some effort I figured it out.

    It gives that error because the Conda environment is somehow using the system Python, from /usr/bin/python3 and /usr/bin/pip3. Check using commands like

    $ which python
    $ which python3
    $ which pip3
    

    You need it to use the instance of Python installed within the active Conda environment. One way to ensure this is to specify a version of Python while creating the Conda environment - this is what I did and it worked. Do something like -

    $ conda create -n env1 python=3.10 
    

    If you already explicitly added Python while creating the Conda environment and you still get the same error, you probably have a different problem, google for - Conda using system python.