Reputation: 2279
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
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
Upvotes: 3
Views: 11299
Reputation: 3979
I had to do the following steps to fix the issue :
1. conda env remove -n <ENV_NAME> // delete the current environment.
2. conda create -n <ENV_NAME> python=3.10 // recreate it using python version.
3. conda activate <ENV_NAME>
4. pip freeze --user > packages.txt // get the packages for the user
5. pip uninstall -r packages.txt // uninstall
6. pip install -r packages.txt // install
Upvotes: 1
Reputation: 1
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.
Upvotes: 0
Reputation: 41
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.
Upvotes: 0
Reputation: 2279
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 ...
Upvotes: 3
Reputation: 612
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
.
Upvotes: 0