0
votes

I installed matplotlib using terminal on my mac and it was successfully installed. However, when I try to import matplotlib, it produces the ModuleNotFound error. The following are my codes and error messages.

Terminal:

(myProject) bash-3.2$ python3 -m pip install -U matplotlib

Looking in indexes: https://pypi.doubanio.com/simple Requirement already up-to-date: matplotlib in /Users/zbao/.local/share/virtualenvs/myProject-opsBTjit/lib/python3.8/site-packages (3.1.3) Requirement already satisfied, skipping upgrade: python-dateutil>=2.1 in /Users/zbao/.local/share/virtualenvs/myProject-opsBTjit/lib/python3.8/site-packages (from matplotlib) (2.8.1) Requirement already satisfied, skipping upgrade: kiwisolver>=1.0.1 in /Users/zbao/.local/share/virtualenvs/myProject-opsBTjit/lib/python3.8/site-packages (from matplotlib) (1.1.0) Requirement already satisfied, skipping upgrade: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /Users/zbao/.local/share/virtualenvs/myProject-opsBTjit/lib/python3.8/site-packages (from matplotlib) (2.4.6) Requirement already satisfied, skipping upgrade: cycler>=0.10 in /Users/zbao/.local/share/virtualenvs/myProject-opsBTjit/lib/python3.8/site-packages (from matplotlib) (0.10.0) Requirement already satisfied, skipping upgrade: numpy>=1.11 in /Users/zbao/.local/share/virtualenvs/myProject-opsBTjit/lib/python3.8/site-packages (from matplotlib) (1.18.1) Requirement already satisfied, skipping upgrade: six>=1.5 in /Users/zbao/.local/share/virtualenvs/myProject-opsBTjit/lib/python3.8/site-packages (from python-dateutil>=2.1->matplotlib) (1.14.0) Requirement already satisfied, skipping upgrade: setuptools in /Users/zbao/.local/share/virtualenvs/myProject-opsBTjit/lib/python3.8/site-packages (from kiwisolver>=1.0.1->matplotlib) (45.2.0)

IDLE:

import matplotlib

Traceback (most recent call last): File "", line 1, in import matplotlib ModuleNotFoundError: No module named 'matplotlib'

Thanks for the help! If anything else is needed please let me know. Sorry I am still very new to Python.

1
Are you definitely using the correct version of Python? Mac has the system python (2.7) by default. type which python in the terminal to see which one is being used.Nick H
Thank you for the response! Here is the messgae I get after I ran which python: /usr/bin/pythonBunZ

1 Answers

0
votes

From the look of your traceback, it looks like you have installed matplotlib inside a virtualenv. So your choices are:

  1. run your idle from your virtualenv: myproject/bin/python3 then you should be able to import matplotlib
  2. run sudo pip install matplotlib. This will install matplotlib into your system Python(2.7) so you can run from your system python. (/usr/bin/python)

Hope this helps