{"id":1061,"hash":"bede90c9c9b0f95867e5f90ad44ae4c748572944719426ba67e1d68fb80dc134","pattern":"ImportError: No module named matplotlib.pyplot","full_message":"I am currently practicing matplotlib. This is the first example I practice.\n\n#!/usr/bin/python\n\nimport matplotlib.pyplot as plt\n\nradius = [1.0, 2.0, 3.0, 4.0]\narea = [3.14159, 12.56636, 28.27431, 50.26544]\n\nplt.plot(radius, area)\nplt.show()\n\nWhen I run this script with python ./plot_test.py, it shows plot correctly. However, I run it by itself, ./plot_test.py, it throws the followings:\n\nTraceback (most recent call last):\n  File \"./plot_test.py\", line 3, in <module>\n    import matplotlib.pyplot as plt\nImportError: No module named matplotlib.pyplot\n\nDoes python look for matplotlib in different locations?\n\nThe environment is:\n\nMac OS X 10.8.4 64bit\nbuilt-in python 2.7\n\nnumpy, scipy, matplotlib is installed with:\n\nsudo port install py27-numpy py27-scipy py27-matplotlib \\\npy27-ipython +notebook py27-pandas py27-sympy py27-nose","ecosystem":"pypi","package_name":"matplotlib","package_version":null,"solution":"You have two pythons installed on your machine, one is the standard python that comes with Mac OSX and the second is the one you installed with ports (this is the one that has matplotlib installed in its library, the one that comes with macosx does not).\n\n/usr/bin/python\n\nIs the standard mac python and since it doesn't have matplotlib you should always start your script with the one installed with ports.\n\nIf python your_script.py works then change the #! to:\n\n#!/usr/bin/env python\n\nOr put the full path to the python interpreter that has the matplotlib installed in its library.","confidence":0.95,"source":"stackoverflow","source_url":"https://stackoverflow.com/questions/18176591/importerror-no-module-named-matplotlib-pyplot","votes":274,"created_at":"2026-04-19T04:52:15.478417+00:00","updated_at":"2026-04-19T04:52:15.478417+00:00"}