Pip not working in anaconda environment

I followed the book to create an environment “gluon” using anaconda. after activating the gluon, i checked the pip installation and got the following error message:

~/anaconda3/envs/gluon$ pip --Version
Traceback (most recent call last):
File “/home/lance/anaconda3/envs/gluon/bin/pip”, line 7, in
from pip._internal.cli.main import main
ModuleNotFoundError: No module named ‘pip._internal.cli.main’

can anybody help on this ? many thanks!

Lance


my computer information:
thinkpad x1 extreme
ubuntu 18.04
Anaconda

conda install pip -U

Do these before you ask!

You maybe need to reinstall pip?

Hi @lance, can I know if you follow this instruction: https://d2l.ai/chapter_installation/index.html? If you did, let me know which step caused you the error.

Hi, Steven, I did the command you mentioned and got the following message:

(gluon) lance@lance-ThinkPad-X1-Extreme:~$ pip --version
Traceback (most recent call last):
File “/home/lance/anaconda3/envs/gluon/bin/pip”, line 7, in
from pip._internal.cli.main import main
ModuleNotFoundError: No module named ‘pip._internal.cli.main’

Hi, I read the instruction you mentioned, the following is what I did:

  1. I installed anaconda (not miniconda), in a standard way. I had anaconda installed before I picked up the d2l book. I assume anaconda should work as fine as miniconda for d2l. If not, please let me know.
    My anaconda installation directory was: /home/lance/anaconda3

  2. I downloaded the book file package and unzipped it at:
    /home/lance/Documents/Dive-into-Deep-Learning/d2l-zh/

  3. I created an environment “gluon” using the the file “environment.yml” as instructed in the book.

  4. I activated “gluon”, and run: “pip --version”, and got the following message:
    (gluon) lance@lance-ThinkPad-X1-Extreme:~$ pip --version
    Traceback (most recent call last):
    File “/home/lance/anaconda3/envs/gluon/bin/pip”, line 7, in
    from pip._internal.cli.main import main

  5. I run the command “conda install pip -y”, and got the message:
    WARNING: The conda.compat module is deprecated and will be removed in a future release.
    Collecting package metadata: done
    Solving environment: done
    ==> WARNING: A newer version of conda exists. <==
    current version: 4.6.11
    latest version: 4.8.5
    Please update conda by running
    $ conda update -n base -c defaults conda
    All requested packages already installed.

  6. after that, I repeated 4) to check pip, but still got the same message:
    (gluon) lance@lance-ThinkPad-X1-Extreme:~$ pip --version
    Traceback (most recent call last):
    File “/home/lance/anaconda3/envs/gluon/bin/pip”, line 7, in
    from pip._internal.cli.main import main
    ModuleNotFoundError: No module named ‘pip._internal.cli.main’

Did you update?
conda update -n base -c defaults conda

I just updated conda using the command “conda update -n base -c defaults conda”. It has been done now.

then I tried installing pip again:
(gluon) lance@lance-ThinkPad-X1-Extreme:~/anaconda3/envs/gluon$ conda install pip -y
Collecting package metadata (repodata.json): done
Solving environment: done
All requested packages already installed.

when I checked pip version, still not working:
(gluon) lance@lance-ThinkPad-X1-Extreme:~/anaconda3/envs/gluon$ pip --version
Traceback (most recent call last):
File “/home/lance/anaconda3/envs/gluon/bin/pip”, line 7, in
from pip._internal.cli.main import main
ModuleNotFoundError: No module named ‘pip._internal.cli.main’

Hi @lance, theoretically anaconda should include all the packages of miniconda, however, sometimes there are small variations. Could you follow the instruction I mentioned earlier and try with miniconda? Please let me know if it still doesnt work.

try
python -m pip install --upgrade pip
google first…

Steven, this solved the problem. thanks!