Python OSError:[Errno 24]打开的文件过多

时间:2016-01-15 22:34:58

标签: macos python-3.x matplotlib

我在Mac OS 10.11.2上使用Ipython Notebook。我运行Python 3.5.1和Matplotlib 1.5.1以及Seaborn版本0.6.0:

%matplotlib inline

import matplotlib.pyplot as plt

import seaborn as sns

我最近在使用Matplotlib / Seaborn进行绘图时遇到了问题。在同一笔记本中生成几个图后,生成我最新绘图的笔记本单元格因错误而崩溃:

OSError: [Errno 24] Too many open files: '/Library/Fonts/Arial.ttf'

我仍然可以运行其他单元格但每次尝试在此笔记本中绘制内容时都会引发相同的错误,直到我重新启动它。

我尝试通过运行来增加文件限制:

sudo launchctl limit maxfiles 10000000 10000000

这似乎有点帮助问题持续存在。关于如何一劳永逸地解决问题的任何建议都将受到赞赏。谢谢 !

以下是错误的确切输出:

OSError                                   Traceback (most recent call last)
/Users/spfraib/anaconda/lib/python3.5/site-packages/IPython/core/formatters.py in __call__(self, obj)

/Users/spfraib/anaconda/lib/python3.5/site-packages/IPython/core/pylabtools.py in <lambda>(fig)

/Users/spfraib/anaconda/lib/python3.5/site-packages/IPython/core/pylabtools.py in print_figure(fig, fmt, bbox_inches, **kwargs)

/Users/spfraib/anaconda/lib/python3.5/site-packages/matplotlib/backend_bases.py in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, **kwargs)

/Users/spfraib/anaconda/lib/python3.5/site-packages/matplotlib/backends/backend_agg.py in print_png(self, filename_or_obj, *args, **kwargs)

/Users/spfraib/anaconda/lib/python3.5/site-packages/matplotlib/backends/backend_agg.py in draw(self)

/Users/spfraib/anaconda/lib/python3.5/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)

/Users/spfraib/anaconda/lib/python3.5/site-packages/matplotlib/figure.py in draw(self, renderer)

/Users/spfraib/anaconda/lib/python3.5/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)

/Users/spfraib/anaconda/lib/python3.5/site-packages/matplotlib/axes/_base.py in draw(self, renderer, inframe)

/Users/spfraib/anaconda/lib/python3.5/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)

/Users/spfraib/anaconda/lib/python3.5/site-packages/matplotlib/axis.py in draw(self, renderer, *args, **kwargs)

/Users/spfraib/anaconda/lib/python3.5/site-packages/matplotlib/axis.py in _get_tick_bboxes(self, ticks, renderer)

/Users/spfraib/anaconda/lib/python3.5/site-packages/matplotlib/text.py in get_window_extent(self, renderer, dpi)

/Users/spfraib/anaconda/lib/python3.5/site-packages/matplotlib/text.py in _get_layout(self, renderer)

/Users/spfraib/anaconda/lib/python3.5/site-packages/matplotlib/backends/backend_agg.py in get_text_width_height_descent(self, s, prop, ismath)

/Users/spfraib/anaconda/lib/python3.5/site-packages/matplotlib/mathtext.py in parse(self, s, dpi, prop)

/Users/spfraib/anaconda/lib/python3.5/site-packages/matplotlib/mathtext.py in __init__(self, *args, **kwargs)

/Users/spfraib/anaconda/lib/python3.5/site-packages/matplotlib/mathtext.py in __init__(self, *args, **kwargs)

/Users/spfraib/anaconda/lib/python3.5/site-packages/matplotlib/mathtext.py in __init__(self, default_font_prop, mathtext_backend)

OSError: [Errno 24] Too many open files: '/Library/Fonts/Arial.ttf'

2 个答案:

答案 0 :(得分:1)

在开始ipython之前尝试增加文件限制,例如> atan(c(1,1.5,2)) [1] 0.7853982 0.9827937 1.1071487 > f(c(1,1.5,2)) [1] 0.6648275 0.9972412 1.3296550 > f(1) [1] 0.7852855 > f(1.5) [1] 0.9828134 > f(2) [1] 1.107888 最多4096个文件描述符。 El Capitan默认限制为256个文件描述符。

答案 1 :(得分:0)

博客post中描述的解决方案为我解决了问题。我在使用Sublime Text编辑器时遇到了这些错误,它使用了一个python驱动的插件系统。

使用以下内容创建/Library/LaunchDaemons/limit.maxfiles.plist

<?xml version="1.0" encoding="UTF-8"?>  
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"  
        "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">  
  <dict>
    <key>Label</key>
    <string>limit.maxfiles</string>
    <key>ProgramArguments</key>
    <array>
      <string>launchctl</string>
      <string>limit</string>
      <string>maxfiles</string>
      <string>524288</string>
      <string>524288</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
    <key>ServiceIPC</key>
    <false/>
  </dict>
</plist>  

使用以下内容创建/Library/LaunchDaemons/limit.maxproc.plist

<?xml version="1.0" encoding="UTF-8"?>  
<!DOCTYPE plist PUBLIC "-//Apple/DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">  
<plist version="1.0">
  <dict>
    <key>Label</key>
      <string>limit.maxproc</string>
    <key>ProgramArguments</key>
      <array>
        <string>launchctl</string>
        <string>limit</string>
        <string>maxproc</string>
        <string>2048</string>
        <string>2048</string>
      </array>
    <key>RunAtLoad</key>
      <true />
    <key>ServiceIPC</key>
      <false />
  </dict>
</plist>

确保权限正确,

-rw-r--r--   1 root  wheel   541 Oct  5 14:14 limit.maxfiles.plist
-rw-r--r--   1 root  wheel   586 Oct  5 14:14 limit.maxproc.plist

然后:

sudo launchctl load -w /Library/LaunchDaemons/limit.maxfiles.plist
sudo launchctl load -w /Library/LaunchDaemons/limit.maxproc.plist

起初,它对我不起作用(检查ulimit -a),但重新启动后,它就像一个魅力。没有更烦人的错误。