I’m trying to run the following python script (I’m using Vim):
import numpy as np; import scipy as sp; from scipy import misc; import matplotlib.pyplot as plt; image = misc.imread('test_image.jpg'); np.fliplr(image); plt.imshow(image);
When I do, I get the following:
Traceback (most recent call last): File "test.py", line 4, in <module> import matplotlib.pyplot as plt; File "/Library/Python/2.7/site-packages/matplotlib/pyplot.py", line 24, in <module> import matplotlib.colorbar File "/Library/Python/2.7/site-packages/matplotlib/colorbar.py", line 29, in <module> import matplotlib.collections as collections File "/Library/Python/2.7/site-packages/matplotlib/collections.py", line 23, in <module> import matplotlib.backend_bases as backend_bases File "/Library/Python/2.7/site-packages/matplotlib/backend_bases.py", line 50, in <module> import matplotlib.textpath as textpath File "/Library/Python/2.7/site-packages/matplotlib/textpath.py", line 11, in <module> import matplotlib.font_manager as font_manager File "/Library/Python/2.7/site-packages/matplotlib/font_manager.py", line 53, in <module> from matplotlib import ft2font ImportError: dlopen(/Library/Python/2.7/site-packages/matplotlib/ft2font.so, 2): Library not loaded: @loader_path/../../../libfreetype.6.dylib Referenced from: /Library/Python/2.7/site-packages/matplotlib/ft2font.so Reason: image not found shell returned 1
I tried reinstalling brew
, reinstalling freetype
, matplotlib
, and numpy
in brew
, and I uninstalled MacPorts with no change in the error. Suggestions?
EDIT: After uninstalling MacPorts and then doing another reinstall of brew
, I now get this error instead.
Fatal Python error: PyThreadState_Get: no current thread
Command terminated
The error only appears when I import
matplotlib
, so I’m guessing the issue is with matplotlib
. I will try to reinstall it with brew
.
EDIT2: I’ve been trying from this page to no avail, but I think my error is probably related to that one.
Advertisement
Answer
Fixed it… sort of.
Fixed it.
I uninstalled with brew uninstall matplotlib
and then installed with pip install matplotlib
. The pip
version now works. although I think something is wrong with my code because I don’t get an image output.
I uninstalled all of my installations of python
and then installed ipython
, which worked fine. Also, I was forgetting to add plt.show();
after my imshow();
commands… :-( …. but at least someone else has made this mistake before me …
Refer to this page for very thorough help with any matplotlib
imshow
issues:
matplotlib does not show my drawings although I call pyplot.show()