【问题标题】:Error import pylab in python 2.5在 python 2.5 中导入 pylab 时出错
【发布时间】:2014-03-06 16:19:59
【问题描述】:

我尝试在 python 2.5 上运行这个简单的程序并得到以下错误,我不确定发生了什么。

代码:

import pylab
pylab.figure(1) # make figure 1 the current figure
pylab.plot([1,2,3,4], [1,7,3,5]) # draw on figure 1
pylab.show() # show figure on screen

错误:

Traceback (most recent call last):
  File "/Users/sebastiancarrasco/Desktop/Courses/6.00.2x/Week1/plotting-seg1.py", line 3, in <module>
    pylab.figure(1) # make figure 1 the current figure
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/pyplot.py", line 270, in figure
    **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/backends/backend_tkagg.py", line 85, in new_figure_manager
    figManager = FigureManagerTkAgg(canvas, num, window)
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/backends/backend_tkagg.py", line 403, in __init__
    self.toolbar = NavigationToolbar2TkAgg( canvas, self.window )
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/backends/backend_tkagg.py", line 670, in __init__
    NavigationToolbar2.__init__(self, canvas)
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/backend_bases.py", line 2273, in __init__
    self._init_toolbar()
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/backends/backend_tkagg.py", line 719, in _init_toolbar
    command=self.home)
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/backends/backend_tkagg.py", line 702, in _Button
    im = Tk.PhotoImage(master=self, file=file)
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/lib-tk/Tkinter.py", line 3294, in __init__
    Image.__init__(self, 'photo', name, cnf, master, **kw)
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/lib-tk/Tkinter.py", line 3250, in __init__
    self.tk.call(('image', 'create', imgtype, name,) + options)
TclError: couldn't open "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/mpl-data/images/home.ppm": permission denied

【问题讨论】:

  • 您的用户似乎没有打开home.ppm 文件的权限。您可能必须为您的用户单独安装 matplotlib 模块或将其安装在 python 虚拟环境中。
  • 您还使用了一个众所周知的对安装科学 python 堆栈不友好的 mac。

标签: python macos matplotlib python-2.5


【解决方案1】:

对于遇到此问题并遇到此页面的其他任何人:我最终找到了答案here。长话短说:安装程序的一些问题弄乱了“图像”文件夹中所有文件的权限。您所要做的就是更改权限以赋予自己读取权限。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-06
    • 1970-01-01
    • 2018-09-15
    • 2020-06-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多