我已经用tkinter完成了相当完整的GUI脚本,该脚本进行了一些计算,创建了多个matplotlib图片并将其粘贴到pdf中。由于没有Python的计算机可以使用该文件,因此我尝试在Windows 7和Python 3.6.8中使用Pyinstaller v.3.5创建一个exe。我的原始代码从未成功创建exe,因此我只检查了代码的一小部分。但是,当我尝试创建只做一个绘图的Excel(当然,它在Spyder中有效)时:
import matplotlib.pyplot as plt
plt.plot([1,1],[2,2],'o')
这段代码也无法正常工作。运行cmd需要很长时间,最后它不会创建任何提供此输出的exe。我只是尝试单独导入另一个库,例如numpy和tkinter,并且可以正常工作,但是matplotlib(v3.0)带来了似乎所有的问题
1399647 INFO: Removing import of PyQt4 from module IPython.external.qt_loaders
1399648 INFO: Excluding import 'PySide'
1399660 INFO: Removing import of PySide from module IPython.external.qt_loader
s
1399661 INFO: Excluding import 'PyQt5'
1399673 INFO: Removing import of PyQt5.QtSvg from module IPython.external.qt_loaders
1399674 INFO: Removing import of PyQt5.QtWidgets from module IPython.external.
qt_loaders
1399674 INFO: Removing import of PyQt5.QtCore from module IPython.external.qt_
loaders
1399674 INFO: Removing import of PyQt5.QtGui from module IPython.external.qt_l
oaders
1399674 INFO: Removing import of PyQt5 from module IPython.external.qt_loaders
1399675 INFO: Loading module hook "hook-jedi.py"...
1399709 INFO: Loading module hook "hook-jinja2.py"...
1399740 INFO: Loading module hook "hook-jsonschema.py"...
1399767 INFO: Loading module hook "hook-lib2to3.py"...
1399798 INFO: Loading module hook "hook-llvmlite.py"...
1399851 INFO: Loading module hook "hook-lxml.etree.py"...
1399857 INFO: Loading module hook "hook-markdown.py"...
1400816 INFO: Loading module hook "hook-matplotlib.backends.py"...
1406587 INFO: Matplotlib backend "GTK3Agg": ignored
cairo backend requires that cairocffi or pycairo is installed
1409444 INFO: Matplotlib backend "GTK3Cairo": ignored
cairo backend requires that cairocffi or pycairo is installed
1413335 INFO: Matplotlib backend "MacOSX": ignored
cannot import name '_macosx'
1425606 INFO: Matplotlib backend "nbAgg": added
1429250 INFO: Matplotlib backend "Qt4Agg": added
1432155 INFO: Matplotlib backend "Qt4Cairo": ignored
cairo backend requires that cairocffi or pycairo is installed
1435849 INFO: Matplotlib backend "Qt5Agg": added
1438826 INFO: Matplotlib backend "Qt5Cairo": ignored
cairo backend requires that cairocffi or pycairo is installed
1441990 INFO: Matplotlib backend "TkAgg": added
1445547 INFO: Matplotlib backend "TkCairo": ignored
cairo backend requires that cairocffi or pycairo is installed
1449979 INFO: Matplotlib backend "WebAgg": added
1453197 INFO: Matplotlib backend "WX": ignored
No module named 'wx'
1455924 INFO: Matplotlib backend "WXAgg": ignored
No module named 'wx'
1458797 INFO: Matplotlib backend "WXCairo": ignored
No module named 'wx'
1462670 INFO: Matplotlib backend "agg": added
1466793 INFO: Matplotlib backend "cairo": ignored
cairo backend requires that cairocffi or pycairo is installed
1471658 INFO: Matplotlib backend "pdf": added
1476366 INFO: Matplotlib backend "pgf": added
1479970 INFO: Matplotlib backend "ps": added
1482802 INFO: Matplotlib backend "svg": added
1485791 INFO: Matplotlib backend "template": added
1520246 INFO: Loading module hook "hook-matplotlib.py"...
1522850 INFO: Loading module hook "hook-nbconvert.py"...
1522978 INFO: Loading module hook "hook-nbformat.py"...
1523023 INFO: Loading module hook "hook-netCDF4.py"...
1523062 WARNING: Hidden import "netcdftime" not found!
1523063 INFO: Loading module hook "hook-notebook.py"...
1530256 INFO: Loading module hook "hook-numba.py"...
1535161 INFO: Excluding import 'IPython'
1535187 INFO: Removing import of IPython.utils.path from module numba.caching
1535188 INFO: Removing import of IPython.paths from module numba.caching
1535194 INFO: Excluding import 'scipy'
1535215 INFO: Removing import of scipy.linalg.cython_lapack from module numba.
targets.linalg
1535217 INFO: Removing import of scipy.linalg.cython_blas from module numba.ta
rgets.linalg
1535220 INFO: Loading module hook "hook-numpy.core.py"...
1536807 INFO: Loading module hook "hook-numpy.py"...
1536810 INFO: Loading module hook "hook-pandas.py"...
1543306 INFO: Loading module hook "hook-patsy.py"...
1543316 INFO: Loading module hook "hook-PIL.Image.py"...
1544101 INFO: Loading module hook "hook-PIL.py"...
1544113 INFO: Excluding import 'tkinter'
1544125 INFO: Removing import of tkinter from module PIL.ImageTk
1544127 INFO: Excluding import 'PyQt4'
1544138 INFO: Removing import of PyQt4 from module PIL.ImageQt
1544141 INFO: Import to be excluded not found: 'FixTk'
1544142 INFO: Excluding import 'PySide'
1544153 INFO: Removing import of PySide from module PIL.ImageQt
1544155 INFO: Excluding import 'PyQt5'
1544167 INFO: Removing import of PyQt5.QtCore from module PIL.ImageQt
1544168 INFO: Removing import of PyQt5.QtGui from module PIL.ImageQt
1544170 INFO: Loading module hook "hook-PIL.SpiderImagePlugin.py"...
1544182 INFO: Import to be excluded not found: 'FixTk'
1544183 INFO: Excluding import 'tkinter'
1544193 INFO: Loading module hook "hook-pkg_resources.py"...
1549870 INFO: Loading module hook "hook-pycparser.py"...
1549877 INFO: Loading module hook "hook-pydoc.py"...
1549880 INFO: Loading module hook "hook-pygments.py"...
1553237 INFO: Loading module hook "hook-PyQt5.py"...
1554065 INFO: Loading module hook "hook-PyQt5.QtCore.py"...
1554277 INFO: Loading module hook "hook-PyQt5.QtGui.py"...
1554595 INFO: Loading module hook "hook-PyQt5.QtSvg.py"...
1555126 INFO: Loading module hook "hook-PyQt5.QtWidgets.py"...
1555639 INFO: Loading module hook "hook-pytest.py"...
1560989 INFO: Loading module hook "hook-pythoncom.py"...
1564929 INFO: Loading module hook "hook-pytz.py"...
1566055 INFO: Loading module hook "hook-pywintypes.py"...
1569964 INFO: Loading module hook "hook-scipy.io.matlab.py"...
1569973 INFO: Loading module hook "hook-scipy.linalg.py"...
1569979 INFO: Loading module hook "hook-scipy.py"...
1569998 INFO: Loading module hook "hook-scipy.sparse.csgraph.py"...
1570015 INFO: Loading module hook "hook-scipy.special._ellip_harm_2.py"...
1570018 INFO: Loading module hook "hook-scipy.special._ufuncs.py"...
1570022 INFO: Loading module hook "hook-setuptools.py"...
1575138 INFO: Loading module hook "hook-shelve.py"...
1575147 INFO: Loading module hook "hook-sklearn.metrics.cluster.py"...
1576033 WARNING: Hidden import "sklearn.utils.sparsetools._graph_validation" not
found!
1576034 WARNING: Hidden import "sklearn.utils.sparsetools._graph_tools" not foun
d!
1576037 INFO: Loading module hook "hook-sphinx.py"...
C:\Adrian\WPy64-3680\python-3.6.8.amd64\lib\site-packages\sphinx\websupport\__in
it__.py:25: RemovedInSphinx20Warning: sphinx.websupport module is now provided a
s sphinxcontrib-websupport. sphinx.websupport will be removed at Sphinx-2.0. Ple
ase use the package instead.
RemovedInSphinx20Warning)
1598160 INFO: Loading module hook "hook-sqlalchemy.py"...
1599383 INFO: Found 6 sqlalchemy hidden imports
1599386 WARNING: Hidden import "MySQLdb" not found!
1599415 WARNING: Hidden import "sqlalchemy.sql.functions.func" not found!
1599415 WARNING: Hidden import "sqlalchemy.orm.state", "sqlalchemy.orm.strategie
s" not found!
1599425 INFO: Excluding import 'sqlalchemy.testing'
1599437 INFO: Removing import of sqlalchemy.testing.util from module sqlalchem
y.orm.util
1599437 INFO: Removing import of sqlalchemy.testing.util from module sqlalchem
y.testing
1599438 INFO: Removing import of sqlalchemy.testing.assertsql from module sqla
lchemy.testing
1599438 INFO: Removing import of sqlalchemy.testing from module sqlalchemy.tes
ting
1599438 INFO: Removing import of sqlalchemy.testing.exclusions from module sql
alchemy.testing
1599438 INFO: Removing import of sqlalchemy.testing.assertions from module sql
alchemy.testing
1599438 INFO: Removing import of sqlalchemy.testing.mock from module sqlalchem
y.testing
1599439 INFO: Removing import of sqlalchemy.testing.warnings from module sqlal
chemy.testing
1599439 INFO: Removing import of sqlalchemy.testing.engines from module sqlalc
hemy.testing
1599439 INFO: Removing import of sqlalchemy.testing.config from module sqlalch
emy.testing
1599439 INFO: Removing import of sqlalchemy.testing from module sqlalchemy.tes
ting.config
1599439 INFO: Removing import of sqlalchemy.testing from module sqlalchemy.tes
ting.mock
1599440 INFO: Removing import of sqlalchemy.testing.util from module sqlalchem
y.testing.assertions
1599440 INFO: Removing import of sqlalchemy.testing.assertsql from module sqla
lchemy.testing.assertions
1599440 INFO: Removing import of sqlalchemy.testing from module sqlalchemy.tes
ting.assertions
1599440 INFO: Removing import of sqlalchemy.testing.exclusions from module sql
alchemy.testing.assertions
1599440 INFO: Removing import of sqlalchemy.testing.mock from module sqlalchem
y.testing.assertions
1599440 INFO: Removing import of sqlalchemy.testing.config from module sqlalch
emy.testing.assertions
1599441 INFO: Removing import of sqlalchemy.testing from module sqlalchemy.tes
ting.assertsql
1599441 INFO: Removing import of sqlalchemy.testing from module sqlalchemy.tes
ting.util
1599441 INFO: Removing import of sqlalchemy.testing.engines from module sqlalc
hemy.testing.util
1599441 INFO: Removing import of sqlalchemy.testing.config from module sqlalch
emy.testing.util
1599441 INFO: Removing import of sqlalchemy.testing.util from module sqlalchem
y.testing.engines
1599441 INFO: Removing import of sqlalchemy.testing.assertions from module sql
alchemy.testing.engines
1599442 INFO: Removing import of sqlalchemy.testing from module sqlalchemy.tes
ting.engines
1599442 INFO: Removing import of sqlalchemy.testing.config from module sqlalch
emy.testing.engines
1599444 INFO: Removing import of sqlalchemy.testing from module sqlalchemy.tes
ting.exclusions
1599444 INFO: Removing import of sqlalchemy.testing.config from module sqlalch
emy.testing.exclusions
1599444 INFO: Removing import of sqlalchemy.testing.assertions from module sql
alchemy.testing.warnings
1599444 INFO: Removing import of sqlalchemy.testing from module sqlalchemy.tes
ting.warnings
1599445 INFO: Loading module hook "hook-sqlite3.py"...
1599964 INFO: Loading module hook "hook-sysconfig.py"...
1599969 INFO: Loading module hook "hook-tables.py"...
1599974 INFO: Loading module hook "hook-torch.py"...
1600782 INFO: Loading module hook "hook-win32com.py"...
1601829 INFO: Loading module hook "hook-xml.dom.domreg.py"...
1601835 INFO: Loading module hook "hook-xml.etree.cElementTree.py"...
1601837 INFO: Loading module hook "hook-xml.py"...
1601839 INFO: Loading module hook "hook-zmq.py"...
1639934 WARNING: Hidden import "C1083:" not found!
1640998 WARNING: Hidden import "'io.h':" not found!
1641000 WARNING: Hidden import "or" not found!
1641002 WARNING: Hidden import "such" not found!
1641005 WARNING: Hidden import "Cannot" not found!
1641008 WARNING: Hidden import "directory" not found!
1641011 WARNING: Hidden import "error" not found!
1641014 WARNING: Hidden import "fatal" not found!
1641016 WARNING: Hidden import "No" not found!
1642237 WARNING: Hidden import "open" not found!
1642241 WARNING: Hidden import "_cffi_ext.c" not found!
1642245 WARNING: Hidden import "c:\adrian\wpy64-3680\python-3.6.8.amd64\include\
pyconfig.h(59):" not found!
1643268 WARNING: Hidden import "file:" not found!
1643273 WARNING: Hidden import "file" not found!
1643273 INFO: Loading module hook "hook-_tkinter.py"...
1645455 INFO: checking Tree
1645589 INFO: checking Tree
1646923 INFO: Looking for ctypes DLLs
1647150 WARNING: Ignoring /usr/lib/libc.dylib imported from C:\Adrian\WPy64-3680
\python-3.6.8.amd64\lib\site-packages\monotonic.py - ctypes imports are only sup
ported using bare filenames
1648259 INFO: Analyzing run-time hooks ...
1648355 INFO: Including run-time hook 'pyi_rth__tkinter.py'
1648365 INFO: Including run-time hook 'pyi_rth_win32comgenpy.py'
1648372 INFO: Including run-time hook 'pyi_rth_pyqt5.py'
1648377 INFO: Including run-time hook 'pyi_rth_certifi.py'
1648383 INFO: Including run-time hook 'pyi_rth_traitlets.py'
1648388 INFO: Including run-time hook 'pyi_rth_multiprocessing.py'
1648397 INFO: Including run-time hook 'pyi_rth_pkgres.py'
1648402 INFO: Including run-time hook 'pyi_rth_mplconfig.py'
1648408 INFO: Including run-time hook 'pyi_rth_mpldata.py'
1648617 INFO: Looking for dynamic libraries
1652101 WARNING: lib not found: api-ms-win-core-winrt-string-l1-1-0.dll dependen
cy of C:\Adrian\WPy64-3680\python-3.6.8.amd64\lib\site-packages\numpy\core\vccor
lib140.dll
1655051 WARNING: lib not found: api-ms-win-core-winrt-l1-1-0.dll dependency of C
:\Adrian\WPy64-3680\python-3.6.8.amd64\lib\site-packages\numpy\core\vccorlib140.
dll
1657791 WARNING: lib not found: api-ms-win-core-winrt-error-l1-1-0.dll dependenc
y of C:\Adrian\WPy64-3680\python-3.6.8.amd64\lib\site-packages\numpy\core\vccorl
ib140.dll
1664293 WARNING: lib not found: libzmq.cp36-win_amd64.pyd dependency of C:\Adria
n\WPy64-3680\python-3.6.8.amd64\lib\site-packages\zmq\devices\monitoredqueue.cp3
6-win_amd64.pyd
1670521 WARNING: lib not found: torch_python.dll dependency of C:\Adrian\WPy64-3
680\python-3.6.8.amd64\lib\site-packages\torch\_C.cp36-win_amd64.pyd
1672931 WARNING: lib not found: libzmq.cp36-win_amd64.pyd dependency of C:\Adria
n\WPy64-3680\python-3.6.8.amd64\lib\site-packages\zmq\backend\cython\_version.cp
36-win_amd64.pyd
1675380 WARNING: lib not found: libzmq.cp36-win_amd64.pyd dependency of C:\Adria
n\WPy64-3680\python-3.6.8.amd64\lib\site-packages\zmq\backend\cython\message.cp3
6-win_amd64.pyd
1677465 WARNING: lib not found: libzmq.cp36-win_amd64.pyd dependency of C:\Adria
n\WPy64-3680\python-3.6.8.amd64\lib\site-packages\zmq\backend\cython\_proxy_stee
rable.cp36-win_amd64.pyd
1679841 WARNING: lib not found: libzmq.cp36-win_amd64.pyd dependency of C:\Adria
n\WPy64-3680\python-3.6.8.amd64\lib\site-packages\zmq\backend\cython\utils.cp36-
win_amd64.pyd
1682133 WARNING: lib not found: libzmq.cp36-win_amd64.pyd dependency of C:\Adria
n\WPy64-3680\python-3.6.8.amd64\lib\site-packages\zmq\backend\cython\_device.cp3
6-win_amd64.pyd
1684059 WARNING: lib not found: libzmq.cp36-win_amd64.pyd dependency of C:\Adria
n\WPy64-3680\python-3.6.8.amd64\lib\site-packages\zmq\backend\cython\context.cp3
6-win_amd64.pyd
1686213 WARNING: lib not found: libzmq.cp36-win_amd64.pyd dependency of C:\Adria
n\WPy64-3680\python-3.6.8.amd64\lib\site-packages\zmq\backend\cython\error.cp36-
win_amd64.pyd
1688339 WARNING: lib not found: libzmq.cp36-win_amd64.pyd dependency of C:\Adria
n\WPy64-3680\python-3.6.8.amd64\lib\site-packages\zmq\backend\cython\_poll.cp36-
win_amd64.pyd
1690388 WARNING: lib not found: libzmq.cp36-win_amd64.pyd dependency of C:\Adria
n\WPy64-3680\python-3.6.8.amd64\lib\site-packages\zmq\backend\cython\socket.cp36
-win_amd64.pyd
1693380 INFO: Looking for eggs
1693380 INFO: Using Python library C:\Adrian\WPy64-3680\python-3.6.8.amd64\pytho
n36.dll
1693380 INFO: Found binding redirects:
[]
1694259 INFO: Warnings written to C:\Adrian\WPy64-3680\scripts\build\testingpyin
stal\warn-testingpyinstal.txt
1696521 INFO: Graph cross-reference written to C:\Adrian\WPy64-3680\scripts\buil
d\testingpyinstal\xref-testingpyinstal.html
1697252 INFO: checking PYZ
1697353 INFO: Building because toc changed
1697354 INFO: Building PYZ (ZlibArchive) C:\Adrian\WPy64-3680\scripts\build\test
ingpyinstal\PYZ-00.pyz
1712557 INFO: Building PYZ (ZlibArchive) C:\Adrian\WPy64-3680\scripts\build\test
ingpyinstal\PYZ-00.pyz completed successfully.
1712891 INFO: checking PKG
1712892 INFO: Building PKG because PKG-00.toc is non existent
1712892 INFO: Building PKG (CArchive) PKG-00.pkg
1719503 WARNING: One binary added with two internal names.
1719504 WARNING: ('libGLESv2.dll',
'C:\\Adrian\\WPy64-3680\\python-3.6.8.amd64\\lib\\site-packages\\PyQt5\\Qt\\bin
\\libGLESv2.dll',
'BINARY')
1719504 WARNING: was placed previously at
1719504 WARNING: ('PyQt5\\Qt\\bin\\libGLESv2.dll',
'C:\\Adrian\\WPy64-3680\\python-3.6.8.amd64\\lib\\site-packages\\PyQt5\\Qt\\bin
\\libGLESv2.dll',
'BINARY')
Traceback (most recent call last):
File "C:\Adrian\WPy64-3680\python-3.6.8.amd64\lib\runpy.py", line 193, in _run
_module_as_main
"__main__", mod_spec)
File "C:\Adrian\WPy64-3680\python-3.6.8.amd64\lib\runpy.py", line 85, in _run_
code
exec(code, run_globals)
File "C:\Adrian\WPy64-3680\python-3.6.8.amd64\Scripts\pyinstaller.exe\__main__
.py", line 9, in <module>
File "C:\Adrian\WPy64-3680\python-3.6.8.amd64\lib\site-packages\PyInstaller\__
main__.py", line 111, in run
run_build(pyi_config, spec_file, **vars(args))
File "C:\Adrian\WPy64-3680\python-3.6.8.amd64\lib\site-packages\PyInstaller\__
main__.py", line 63, in run_build
PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
File "C:\Adrian\WPy64-3680\python-3.6.8.amd64\lib\site-packages\PyInstaller\bu
ilding\build_main.py", line 844, in main
build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'
))
File "C:\Adrian\WPy64-3680\python-3.6.8.amd64\lib\site-packages\PyInstaller\bu
ilding\build_main.py", line 791, in build
exec(code, spec_namespace)
File "testingpyinstal.spec", line 35, in <module>
console=True )
File "C:\Adrian\WPy64-3680\python-3.6.8.amd64\lib\site-packages\PyInstaller\bu
ilding\api.py", line 435, in __init__
upx_exclude=self.upx_exclude
File "C:\Adrian\WPy64-3680\python-3.6.8.amd64\lib\site-packages\PyInstaller\bu
ilding\api.py", line 197, in __init__
self.__postinit__()
File "C:\Adrian\WPy64-3680\python-3.6.8.amd64\lib\site-packages\PyInstaller\bu
ilding\datastruct.py", line 158, in __postinit__
self.assemble()
File "C:\Adrian\WPy64-3680\python-3.6.8.amd64\lib\site-packages\PyInstaller\bu
ilding\api.py", line 284, in assemble
pylib_name=pylib_name)
File "C:\Adrian\WPy64-3680\python-3.6.8.amd64\lib\site-packages\PyInstaller\ar
chive\writers.py", line 334, in __init__
super(CArchiveWriter, self).__init__(archive_path, logical_toc)
File "C:\Adrian\WPy64-3680\python-3.6.8.amd64\lib\site-packages\PyInstaller\ar
chive\writers.py", line 62, in __init__
self._finalize()
File "C:\Adrian\WPy64-3680\python-3.6.8.amd64\lib\site-packages\PyInstaller\ar
chive\writers.py", line 94, in _finalize
self.save_trailer(toc_pos)
File "C:\Adrian\WPy64-3680\python-3.6.8.amd64\lib\site-packages\PyInstaller\ar
chive\writers.py", line 441, in save_trailer
tocstr = self.toc.tobinary()
File "C:\Adrian\WPy64-3680\python-3.6.8.amd64\lib\site-packages\PyInstaller\ar
chive\writers.py", line 266, in tobinary
flag, ord(typcd), nm + pad))
struct.error: argument out of range
这是规格文件,以防可能解决此问题。
# -*- mode: python ; coding: utf-8 -*-
import sys
sys.setrecursionlimit(50000)
block_cipher = None
a = Analysis(['testingpyinstal.py'],
pathex=['C:\\Adrian\\WPy64-3680\\scripts'],
binaries=[],
datas=[],
hiddenimports=["FileDialog","tkinter","matplotlib"],
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
[],
name='testingpyinstal',
debug=True,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=True )
除Pyinstaller之外的其他替代方法(我已经使用过cx_freeze,但效果不佳),或者除exe外还欢迎其他建议或替代方法