导入matplotlib的python脚本成功,但脚本的冻结二进制文件失败

2024-09-30 06:31:59 发布

您现在位置:Python中文网/ 问答频道 /正文

我的脚本需要导入numpysklearn、和{},但我无法安装sklearn。对我的问题http://https://stackoverflow.com/questions/38733220/difference-between-scikit-learn-and-sklearn的一个非常有用的回答解释了我需要重新安装numpy。使用pip更新numpy失败,因为OS X 10.11 SIP阻止卸载当前numpy。mfripphttp://https://apple.stackexchange.com/questions/209572/how-to-use-pip-after-the-os-x-el-capitan-upgrade对一个关于pip和SIP的问题的非常有用的回答提供了这个问题的详细解决方案。我完全遵循了这些指令,并使用pip为所有用户重新安装numpymatplotlibscipy和{}。在

当我使用命令运行我完成的脚本时

python DistMatPlot.py Random10A.matrix Random10A.pdf

脚本运行得很好,写入了所有预期的输出文件。在

然而,我总是看到:

"/Library/Python/2.7/site-packages/matplotlib/font_manager.py:273: UserWarning: Matplotlib is building the font cache using fc-list. This may take a moment. warnings.warn('Matplotlib is building the font cache using fc-list. This may take a moment.')"

在更新numpy、matplotlib等之前,我从未见过其他matplotlib脚本。2秒的延迟只是有点烦人。在

我使用pyinstaller编译了一个冻结的二进制文件,在编译过程中,我收到了一些与上面类似的消息。 生成的冻结二进制运行失败,命令为:

./DistMatPlot Random10A.matrix Random10A.pdf

制作如下:

/var/folders/8x/7_zp_33h8xj6td0059b72p9h0000gp/T/_MEIhIysTV/matplotlib/font_manager.py:273: UserWarning: Matplotlib is building the font cache using fc-list. This may take a moment. Traceback (most recent call last): File "", line 13, in File "/Library/Python/2.7/site-packages/PyInstaller/loader/pyimod03_importers.py", line 389, in load_module exec(bytecode, module.dict) File "matplotlib/pyplot.py", line 114, in File "matplotlib/backends/init.py", line 32, in pylab_setup File "/Library/Python/2.7/site-packages/PyInstaller/loader/pyimod03_importers.py", line 389, in load_module exec(bytecode, module.dict) File "matplotlib/backends/backend_macosx.py", line 24, in File "/Library/Python/2.7/site-packages/PyInstaller/loader/pyimod03_importers.py", line 546, in load_module module = imp.load_module(fullname, fp, filename, ext_tuple) RuntimeError: Python is not installed as a framework. The Mac OS X backend will not be able to function correctly if Python is not installed as a framework. See the Python documentation for more information on installing Python as a framework on Mac OS X. Please either reinstall Python as a framework, or try one of the other backends. If you are Working with Matplotlib in a virtual enviroment see 'Working with Matplotlib in Virtual environments' in the Matplotlib FAQ DistMatPlot returned -1

我看过类似的问题,并尝试了他们提出的解决办法,但都没有结果。在

(1)为什么matplotlib每次运行时都需要重建字体缓存?在

(2)当脚本本身成功时,为什么冻结的二进制文件失败?在运行pyinstaller时,除了-F我还需要其他选项吗?在


Tags: piptheinpynumpy脚本matplotlibis
1条回答
网友
1楼 · 发布于 2024-09-30 06:31:59

冻结的二进制文件的问题是“RuntimeError:Python不是作为框架安装的。”

一些帖子讨论了这个问题,并建议在“导入”之前添加这两行matplotlib.pyplot作为plt:

导入matplotlib
matplotlib.使用('TkAgg')

这不起作用,但这一点小小的修改确实奏效了: 导入matplotlib
matplotlib.使用('Agg')

我怀疑'Agg'可能特定于OSX或OSX10.11附带的python版本

相关问题 更多 >

    热门问题