3

When I want to import matplotlib in IDLE. The following error occurs:

ImportError: No module named matplotlib

I use mac, the PATH of python in my bash_profile is:

# Setting PATH for Python 2.7
# The orginal version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
export PATH

Days ago I tried to uninstall python from my mac, so I am not sure if I just damaged built-in python.

How can I fix this problem?

Zezhou Li
  • 107
  • 1
  • 2
  • 12

1 Answers1

1

Two things you can look into.

  • Python env variable for path is PYTHONPATH not just PATH. Change that.
  • Run this command and see the path indeed includes what you need.

    $ python -c 'import sys; print(sys.path)'
    
Hun
  • 3,707
  • 2
  • 15
  • 15
  • Actually I found my matplotlib module in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python. How can I add it into the path file? – Zezhou Li Feb 26 '16 at 17:28
  • Just like you did earlier. But use PYTHONPATH instead of PATH – Hun Feb 26 '16 at 18:20
  • Just a reference, the command works in windows, but need to change the single ' to double ''. – zhihong Mar 21 '18 at 19:45