0

I have downloaded an ipynb file from our tutorial and opened it with jupyter notebook. When I ran this cell containing: import matplotlib.pyplot as plt, I received an error something like module not found error.

I keyed in pip install matplotlib in my terminal then tried to run the cell again but same error shows up. Then I tried to key in:

pip uninstall matplotlib

python -m pip install matplotlib

which I found from some Q&A here in the site then problem solved. I still need more detailed explanation for this. I just want to understand what is going on.

By the way if I key in which python on my terminal (in my working directory), this is what I see:

Python 3.6.8 (v3.6.8:3c6b436a57, Dec 24 2018, 02:04:31) [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin Type "help", "copyright", "credits" or "license" for more information.

>

and if which python, I can see:

/usr/local/bin/python

I just want to understand more so I can set up my tutorial notebooks properly next time especially if I need to import some modules again. Thanks!

toking
  • 320
  • 2
  • 10
  • Just to be clear `python -m pip install ...` works but `pip install ...` doesn't, right? The problem is that for some reason your PC doesn't recognize the `pip` command. Try typing `which pip` to see what it shows. It should show `/usr/local/bin/pip`. – Djib2011 Mar 29 '20 at 08:00
  • This could well be that the `pip` script used doesn't correspond to the `python` interpreter you have in mind. I recommend to never ever call any `pip` script, but instead prefer the safer explicit method of calling _pip_'s executable module for a specific _Python_ interpreter: `path/to/pythonX.Y -m pip somecommand ...` -- https://snarky.ca/why-you-should-use-python-m-pip/ -- https://stackoverflow.com/a/60786507/11138259 – sinoroc Mar 29 '20 at 08:40
  • @Djib2011 Yes to your first question. If I use `pip install ...` I am still getting module note found error. I tried 'which pip' and yes, it showed '/usr/local/bin/pip' – toking Mar 29 '20 at 10:35

1 Answers1

-1

Because even though python is installed in your system and recognized from terminal, pip is not.

So, just install pip.

Using easy_install

sudo easy_install pip
sudo pip install --upgrade pip

Or, sudo python get-pip.py

If it fails,

curl -O https://bootstrap.pypa.io/get-pip.py
sudo python3 get-pip.py

Or, brew install python3 # this also installs pip

Zabir Al Nazi
  • 10,298
  • 4
  • 33
  • 60