Conda: packages are already installed by pip but not shown in conda list

Question:

I use pip install packages in a conda environment.

pip install pygame
Requirement already satisfied: pygame in ./anaconda3/lib/python3.6/site-packages (1.9.4)

where the current directory is /Users/aptx4869. However, when I type conda list, there is nothing in the current environment. What’s wrong with it? Here’s the directory where the environment is at

/Users/aptx4869/anaconda3/envs/rl

Update

I delete the pygame in the root environment and run pip install pygame in the rl conda environment, I receive another message. But pygame still doesn’t show in conda list

 pip install pygame
Collecting pygame
  Using cached https://files.pythonhosted.org/packages/bc/19/57bf1e9c72be4f7afc1add56cc717b7f7fe8ef1b6b5fb58f031a06401d0f/pygame-1.9.4-cp36-cp36m-macosx_10_11_intel.whl
Installing collected packages: pygame
Successfully installed pygame-1.9.4
(rl)

Notice (rl) in the end, this pip command still installs pygame in the root environment

Asked By: Maybe

||

Answers:

I guess that you installed the pygame package into the root environment when you run pip install pygame the first time. So make sure that you have activated the environment into which you want to install packages and then use pip to install the packages. Doing this, you should see the packages in the list of conda list command. Also, you must run the conda list command in the same environment where you run pip install.

Answered By: Gödel

The reason is simply because I didn’t install python and pip in the dl environment, and conda implicitly uses python and pip in the root environment as I command pip install ...

Answered By: Maybe

After facing the same problem, here is the solution that worked for me:
From a separate terminal (not VSCode integrated terminal), with my virtual environment active:

python -m pip install pygame

It is important not simply call pip (or pip3) directly, and it apparently mattered to not do it from VSCode integrated terminal.

Answered By: Roland Sireyjol

I’ve run into this a few times with different packages, and 9 times out of 10 it’s an issue wit managing multiple conda environments.

You can have multiple conda environments active at the same time. If you activate one environment from another environment, it doesn’t necessarily close the first environment. So, say that you create myenv:

(base)$ conda create myenv
(base)$ conda activate myenv
(myenv)$

You work in that environment for a bit, run into some problems, and then realize that it’s easier to start another environment from scratch. If you do

(myenv)$ conda create myenv2
(myenv)$ conda activate myenv2
(myenv2)$

You have activated myenv2. However, you haven’t explicitly closed myenv. You can see this when you deactivate myenv2

(myenv2)$ conda deactivate
(myenv)$ 

I have’t researched this behavior too deeply, but I know that it can create issues with pip installs within conda. Try deactivating your conda environments to base and then activating only the environment of interest. It fixed the problem for me, at least.

Answered By: Lewis Baker
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.