Python 没有名为';matplotlib';将.py文件执行到应用程序时
Python 没有名为';matplotlib';将.py文件执行到应用程序时,python,pyinstaller,Python,Pyinstaller,在此处输入代码我正在尝试使用pyinstaller向应用程序执行.py文件。但是,由于没有名为“matplotlib”的模块,它无法执行脚本。我已经花了两天多的时间来修复它,但对此没有希望。有人能解决我的问题吗?多谢各位 等级库文件如下所示: # -*- mode: python ; coding: utf-8 -*- from PyInstaller.utils.hooks import collect_all datas = [] binaries = [] hiddenimpor
在此处输入代码
我正在尝试使用pyinstaller向应用程序执行.py文件。但是,由于没有名为“matplotlib”的模块,它无法执行脚本。我已经花了两天多的时间来修复它,但对此没有希望。有人能解决我的问题吗?多谢各位
等级库文件如下所示:
# -*- mode: python ; coding: utf-8 -*-
from PyInstaller.utils.hooks import collect_all
datas = []
binaries = []
hiddenimports = []
tmp_ret = collect_all('matplotlib')
datas += tmp_ret[0]; binaries += tmp_ret[1]; hiddenimports += tmp_ret[2]
block_cipher = None
a = Analysis(['apptam.py'],
pathex=['C:\\Users\\dell1\\Desktop\\app'],
binaries=binaries,
datas=datas,
hiddenimports=hiddenimports,
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='apptam',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=True )
使用python,执行以下命令
help(“模块”)
。这将列出python中所有已安装的软件包,如果在其中找不到matplotlib
,这意味着您可能已在其他环境中安装了matplotlib
。您还可以查看导入中是否存在语法错误,以及matplotlib
版本是否与您的python版本兼容。我真的不明白为什么spec
文件中包含此部分-
tmp_ret = collect_all('matplotlib')
datas += tmp_ret[0]; binaries += tmp_ret[1]; hiddenimports += tmp_ret[2]
除非您使用的模块使用matplotlib(?)
我删除了collect\u all
的整个部分,PyInstaller在没有它的情况下正确地收集了所有内容,而collect\u all导致了问题
尝试命令pyinstaller-F apptam.py
。这将在不添加任何内容的情况下重新创建spec文件,并且应该可以正常工作
编辑:
from PyInstaller.utils.hooks import collect_all
datas = []
binaries = []
hiddenimports = []
for required in ('matplotlib', 'PyQt5'):
tmp_ret = collect_all(required)
datas += tmp_ret[0]; binaries += tmp_ret[1]; hiddenimports += tmp_ret[2]
确保分析
具有以下内容,而不是[]
:
binaries=binaries,
datas=datas,
hiddenimports=hiddenimports,
你已经安装了matplotlib了吗?你能检查一下你的python安装中是否有这个模块吗?我已经安装了matplotlib。这就是为什么我无法理解错误的原因。您可以尝试将模块文件夹复制到.py文件所在的根目录下。否则,我可以在快速谷歌搜索中找到,您可能需要添加--collect all标志()谢谢。我听从了你的建议,现在又发生了一个错误。ImportError:无法导入任何qt绑定。你能给我一些提示吗?你的pyinstaller规范文件看起来怎么样?你不需要将任何模块复制到你的项目中。实际上,我顺利地运行了脚本,错误只发生在我使用pyinstaller向我的应用程序执行.py文件时。这就是为什么我不理解这个错误。因为我跟随@Uber的注释,实际上在使用collect_all之后,错误“没有名为'matplotlib'的模块”得到了解决。但是,发生了另一个错误:ImportError:未能导入任何qt绑定。我还不能解决它。@Ng.Alina您是否安装了PyQt模块?如果不安装,请尝试安装PyQt5并尝试使用PyInstaller进行编译。我已经安装了PyQt5,但错误仍然存在。没有解决方案我对此没有任何问题,您可以尝试使用
pyinstaller-F apptam.py
生成一个规范文件,然后将显示hiddenimports=[]
的行更改为hiddenimports=['matplotlib']
。当您运行下一个pyinstaller命令时,您应该在spec文件中执行它:pyinstaller-apptam.spec
。我遵循您的提示。但是发生了另一个错误:未能提取MSVCP140.dll。解压缩导致返回代码-1!我不明白为什么执行起来如此困难