gpt4 book ai didi

python - pyinstaller:使用 matplotlib 构建 python exe

转载 作者:太空宇宙 更新时间:2023-11-03 11:48:29 25 4
gpt4 key购买 nike

我一直在尝试复制这个 post 的例子, 使用 pyinstaller 生成可执行文件,但没有成功。我在 linux 操作系统上。

我尝试构建的 exe 是基于这段代码(之后是 test.py)

from pylab import *
from matplotlib import pyplot as plt

figure(1, figsize=(6,6))
ax = axes([0.1, 0.1, 0.8, 0.8])

labels = 'Frogs', 'Hogs', 'Dogs', 'Logs'
fracs = [15, 30, 45, 10]
explode=(0, 0.05, 0, 0)

pie(fracs, explode=explode, labels=labels,
autopct='%1.1f%%', startangle=90)

title('Pie Chart Example', bbox={'facecolor':'0.8', 'pad':5})

show()

创建我运行的可执行文件

pyinstaller --onefile test.py

我尝试使用 3.0 版(pip 安装中的官方版本)和 3.1.dev 版的 pyinstaller。两者都可以编译,但是当我运行可执行文件时,我得到了

./test 
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/PyInstaller/loader/pyimod03_importers.py", line 363, in load_module
exec(bytecode, module.__dict__)
File "/usr/share/pyshared/pylab.py", line 1, in <module>
from matplotlib.pylab import *
File "/usr/local/lib/python2.7/dist-packages/PyInstaller/loader/pyimod03_importers.py", line 363, in load_module
exec(bytecode, module.__dict__)
File "/usr/share/pyshared/matplotlib/__init__.py", line 157, in <module>
from matplotlib.compat import subprocess
ImportError: No module named compat
test returned -1

我读到一个可能的错误可能与我的 $PYTHONPATH 相关联(参见 post )但即使使用干净的 $PYTHONPATH 环境,我也会遇到同样的错误。

我也不明白为什么可执行文件在/usr/目录中寻找一个文件,而它应该是独立的。

欢迎任何建议。谢谢。

PS:这是用pyinstaller v3.0编译的输出。注意为了让它工作,我必须在文件中注释“PyQt4”和“PyQt5”/usr/local/lib/python2.7/dist-packages/PyInstaller/hooks/hook-PIL.py 中的建议 post .

pyinstaller --onefile test.py 
22 INFO: PyInstaller: 3.0
22 INFO: Python: 2.7.6
22 INFO: Platform: Linux-3.16.0-30-generic-x86_64-with-Ubuntu-14.04-trusty
40 INFO: wrote /home/paugam/Src/stackimage/test.spec
44 INFO: UPX is not available.
45 INFO: Extending PYTHONPATH with /home/paugam/Src/stackimage
45 INFO: checking Analysis
45 INFO: Building Analysis because out00-Analysis.toc is non existent
45 INFO: Initializing module dependency graph...
46 INFO: Initializing module graph hooks...
85 INFO: running Analysis out00-Analysis.toc
102 INFO: Analyzing /home/paugam/Src/stackimage/test.py
135 INFO: Processing pre-find module path hook distutils
6044 INFO: Processing pre-find module path hook site
6044 INFO: site: retargeting to fake-dir '/usr/local/lib/python2.7/dist-packages/PyInstaller/fake-modules'
11904 INFO: Looking for import hooks ...
11906 INFO: Processing hook hook-distutils.py
11906 INFO: Processing hook hook-sysconfig.py
11906 INFO: Processing hook hook-xml.py
11907 INFO: Processing hook hook-PIL.py
11907 INFO: Excluding import 'FixTk'
11910 WARNING: Removing import 'FixTk'
11910 INFO: Excluding import 'Tkinter'
11910 INFO: Excluded import 'PySide' not found
11910 INFO: Processing hook hook-httplib.py
11911 INFO: Processing hook hook-pydoc.py
11911 INFO: Excluding import 'Tkinter'
11911 INFO: Processing hook hook-PyQt4.py
11912 WARNING: Hidden import 'PyQt4._qt' not found (probably old hook)
11912 INFO: Processing hook hook-encodings.py
12264 INFO: Processing hook hook-_tkinter.py
12327 INFO: checking Tree
12327 INFO: Building Tree because out00-Tree.toc is non existent
12327 INFO: Building Tree out00-Tree.toc
12365 INFO: checking Tree
12366 INFO: Building Tree because out01-Tree.toc is non existent
12366 INFO: Building Tree out01-Tree.toc
12380 INFO: Processing hook hook-matplotlib.backends.py
12798 INFO: Matplotlib backend "GTK": added
13108 INFO: Matplotlib backend "GTKAgg": added
13420 INFO: Matplotlib backend "GTKCairo": added
13631 INFO: Matplotlib backend "MacOSX": ignored
cannot import name _macosx
13893 INFO: Matplotlib backend "Qt4Agg": added
14120 INFO: Matplotlib backend "TkAgg": added
14246 INFO: Matplotlib backend "WX": ignored
No module named wx
14464 INFO: Matplotlib backend "WXAgg": ignored
No module named wx

** (-c:4422): WARNING **: Couldn't connect to accessibility bus: Failed to connect to socket /tmp/dbus-psXhVLD3F9: Connection refused
14809 INFO: Matplotlib backend "GTK3Cairo": added

** (-c:4423): WARNING **: Couldn't connect to accessibility bus: Failed to connect to socket /tmp/dbus-psXhVLD3F9: Connection refused
15146 INFO: Matplotlib backend "GTK3Agg": added
15394 INFO: Matplotlib backend "WebAgg": added
15605 INFO: Matplotlib backend "agg": added
15819 INFO: Matplotlib backend "cairo": added
15942 INFO: Matplotlib backend "emf": ignored
No module named backend_emf
16253 INFO: Matplotlib backend "gdk": added
16467 INFO: Matplotlib backend "pdf": added
16754 INFO: Matplotlib backend "pgf": added
16966 INFO: Matplotlib backend "ps": added
17181 INFO: Matplotlib backend "svg": added
17403 INFO: Matplotlib backend "template": added
17844 INFO: Processing pre-safe import module hook gi.repository.GObject
18382 INFO: Processing hook hook-PIL.Image.py
18632 INFO: Processing hook hook-matplotlib.py
18745 INFO: Processing hook hook-xml.dom.domreg.py
18746 INFO: Processing hook hook-PyQt4.QtGui.py
18904 WARNING: Hidden import 'PyQt4._qt' not found (probably old hook)
18905 INFO: Processing hook hook-pytz.py
18905 INFO: Processing hook hook-setuptools.py
18906 INFO: Processing hook hook-xml.sax.py
18906 INFO: Processing hook hook-PIL.SpiderImagePlugin.py
18906 INFO: Excluded import 'FixTk' not found
18906 INFO: Excluding import 'Tkinter'
18907 INFO: Processing hook hook-PyQt4.QtCore.py
18939 WARNING: Hidden import 'PyQT4._qt' not found (probably old hook)
18940 INFO: Processing hook hook-xml.dom.py
18940 INFO: Processing hook hook-gtk.py
18941 WARNING: Hidden import 'gtkglext' not found (probably old hook)
18942 WARNING: Hidden import 'gdkgl' not found (probably old hook)
18943 WARNING: Hidden import 'gdkglext' not found (probably old hook)
18943 WARNING: Hidden import 'gtk.gdk' not found (probably old hook)
18944 WARNING: Hidden import 'gtk.gtkgl' not found (probably old hook)
18944 WARNING: Hidden import 'gtk.gtkgl._gtkgl' not found (probably old hook)
18945 WARNING: Hidden import 'gtkgl' not found (probably old hook)
19008 INFO: Processing hook hook-gi.repository.GObject.py
19076 INFO: Processing pre-safe import module hook gi.repository.GLib
19101 WARNING: Hidden import 'gi._gobject.option' not found (probably old hook)
19101 INFO: Processing hook hook-gi.py
19102 WARNING: Hidden import 'gi._error' not found (probably old hook)
19102 INFO: Processing hook hook-gi.repository.GLib.py
19216 INFO: Looking for ctypes DLLs
19261 WARNING: library rpcrt4.dll required via ctypes not found
19303 INFO: Analyzing run-time hooks ...
19318 INFO: Including run-time hook 'pyi_rth_pkgres.py'
19320 INFO: Including run-time hook 'pyi_rth__tkinter.py'
19321 INFO: Including run-time hook 'pyi_rth_gi.py'
19321 INFO: Including run-time hook 'pyi_rth_qt4plugins.py'
19323 INFO: Including run-time hook 'pyi_rth_mplconfig.py'
19324 INFO: Including run-time hook 'pyi_rth_mpldata.py'
19345 INFO: Looking for dynamic libraries
21278 INFO: Looking for eggs
21278 INFO: Python library not in binary depedencies. Doing additional searching...
21314 INFO: Using Python library /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0
21347 INFO: Warnings written to /home/paugam/Src/stackimage/build/test/warntest.txt
21354 INFO: checking PYZ
21354 INFO: Building PYZ because out00-PYZ.toc is non existent
21355 INFO: Building PYZ (ZlibArchive) /home/paugam/Src/stackimage/build/test/out00-PYZ.pyz
22059 INFO: checking PKG
22059 INFO: Building PKG because out00-PKG.toc is non existent
22059 INFO: Building PKG (CArchive) out00-PKG.pkg
40123 INFO: Bootloader /usr/local/lib/python2.7/dist-packages/PyInstaller/bootloader/Linux-64bit/run
40123 INFO: checking EXE
40123 INFO: Building EXE because out00-EXE.toc is non existent
40123 INFO: Building EXE from out00-EXE.toc
40123 INFO: Appending archive to EXE /home/paugam/Src/stackimage/dist/test

最佳答案

我卸载了 matplotlib 并将其重新安装到版本 1.5.1 并且它工作了。这似乎是 1.4.1- 版本中的错误。引用here .

关于python - pyinstaller:使用 matplotlib 构建 python exe,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33654782/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com