user1876864
user1876864

Reputation: 465

python matplotlib error when trying to plot: matplotlib.gif cannot be found

I'm using PyDev with Eclipse on Win7 32bit (Python version is 2.7.3). I also have Scipy and Matplotlib installed. Now, what I'm trying to do is to save the plotted data as a pdf file. Here is a code sample, although it is not really relevant for my problem:

import scipy as sp
import matplotlib.pyplot as plt
from scipy.io import loadmat

fname = "calc.mat"
data = loadmat(fname)
train_acc, test_acc = data['train'], data['test']
# plot results
fig = plt.figure(1,figsize=(12,4))
fig.clf()

# plot the error
ax1 = fig.add_subplot(1,2,1)
ax1.boxplot(sp.hstack((train_acc, test_acc)))
plt.savefig('bcc.pdf')

The code is pretty simple: load some data from a mat-file, create a plot and store it as an image. Now, when trying to execute the code in Eclipse I'm getting the following error:

 File "C:\Users\Kseniya\workspace\BrainComputerInterfacing\src\bci.py", line 223, in test2
 fig = plt.figure(1,figsize=(12,4))
 File "C:\Programme\Python27\lib\site-packages\matplotlib\pyplot.py", line 343, in figure
**kwargs)
 File "C:\Programme\Python27\lib\site-packages\matplotlib\backends\backend_tkagg.py", line 79, in new_figure_manager
return new_figure_manager_given_figure(num, figure)
 File "C:\Programme\Python27\lib\site-packages\matplotlib\backends\backend_tkagg.py", line 96, in new_figure_manager_given_figure
icon_img = Tk.PhotoImage(file=icon_fname)
 File "C:\Programme\Python27\lib\lib-tk\Tkinter.py", line 3244, in __init__
Image.__init__(self, 'photo', name, cnf, master, **kw)
 File "C:\Programme\Python27\lib\lib-tk\Tkinter.py", line 3200, in __init__
self.tk.call(('image', 'create', imgtype, name,) + options)
_tkinter.TclError: couldn't open "C:\Programme\Python27\lib\site-packages\matplotlib\mpl-data\images\matplotlib.gif": no such file or directory

Seems like the file matplotlib.gif cannot be found or opened, although it is present. If I run the script from the console, I do not get any errors and the script terminates without any errors, creating the image file correctly. So, this seems to be a PyDev error. Does anyone have a clue how to fix it? Many thanks in advance!

Upvotes: 2

Views: 1586

Answers (1)

Janne Karila
Janne Karila

Reputation: 25207

You have installed Python under the Program files folder in Windows, which can cause exactly this kind of issues where one program complains about a missing file while another program shows you the file right there.

This happens because the UAC system in Windows tries to protect the folder from writes without completely denying write access. Instead it redirects writes to so-called virtualized folders in some circumstances.

Installing Python to the default location C:\Python27 avoids this issue.

Upvotes: 2

Related Questions