Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
157 views
in Technique[技术] by (71.8m points)

python - ImportError: No module named backend_tkagg

I have such imports and code:

import pandas as pd
import numpy as np
import statsmodels.formula.api as sm
import matplotlib.pyplot as plt    


#Read the data from pydatasets repo using Pandas
url = './file.csv'
white_side = pd.read_csv(url)    
#Fitting the model    
model = sm.ols(formula='budget ~ article_size',
               data=white_side,
               subset=white_side['producer'] == "Peter Jackson")
fitted = model.fit()
print fitted.summary()

After execution of this code I have such errors:

/usr/bin/python2.7 /home/seth/PycharmProjects/osiris_project/PMN_way/start.py
Traceback (most recent call last):
  File "/home/seth/PycharmProjects/osiris_project/PMN_way/start.py", line 5, in <module>
    import matplotlib.pyplot as plt
  File "/usr/lib64/python2.7/site-packages/matplotlib/pyplot.py", line 98, in <module>
    _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
  File "/usr/lib64/python2.7/site-packages/matplotlib/backends/__init__.py", line 25, in pylab_setup
    globals(),locals(),[backend_name])
ImportError: No module named backend_tkagg

Process finished with exit code 1

I`m using openSUSE and pycharm community edition latest version with installed pandas, numpy, etc How can i fix this problem?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I've seen this before, also on openSUSE (12.3). The fix is to edit the default matplotlibrc file.

Here's how you find where the default matplotlibrc file lives, and where it lives on my machine:

>>> import matplotlib
>>> matplotlib.matplotlib_fname()
'/usr/lib64/python2.7/site-packages/matplotlib/mpl-data/matplotlibrc'

The backend setting is the first configuration option in this file. Change it from TkAgg to Agg, or to some other backend you have installed on your system. The comments in the matplotlibrc file list all backends supported by matplotlib.

The backend specified in this file is only the default; you can still change it at runtime by adding the following two lines, before any other matplotlib import:

import matplotlib
matplotlib.use("Agg")  # or whichever backend you wish to use

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...