1 回答

TA貢獻1813條經驗 獲得超2個贊
那么你還在為此苦苦掙扎嗎?
您需要更新規范文件的“data”和“hiddenimports”部分,以確保庫被導入。我在下面向您展示了我的(效果很好)。您需要修改它以包含 openpyxl、tkinter 和 pandas。
a = Analysis(['main.py'],
pathex=['C:\\Users\\user\\PycharmProjects\\PlotlyExample'],
binaries=[],
datas=[('C:\\Users\\user\\PycharmProjects\\PlotlyExample\\venv\\Lib\\site-packages\\plotly\\', 'plotly'),
('C:\\Users\\user\\PycharmProjects\\PlotlyExample\\venv\\Lib\\site-packages\\kaleido\\', 'kaleido'),
('C:\\Users\\user\\PycharmProjects\\PlotlyExample\\venv\\Lib\\site-packages\\pptx\\', 'pptx'),],
hiddenimports=['pandas','numpy','plotly','pptx'],
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False)
實際上,我遇到了與您關于plotly.json 相同的錯誤,所以我知道上述解決方案有效。:)
同樣重要的是,如果您要導出靜態圖像,請在規范文件中包含 Kaleido 或 Orcas。我正在使用 Kaleido,因此您可以在我的規范文件設置中看到它。
然后通過以下方式運行 PyInstaller: pyinstaller main.spec --clean
其中 main.spec 是您的規范文件(更改名稱)。
編輯:為了讓事情變得更容易,這是我的整個規范文件:
# -*- mode: python ; coding: utf-8 -*-
# Command to compile the spec and python files
# pyinstaller main.spec --clean --onefile
block_cipher = None
a = Analysis(['main.py'],
pathex=['C:\\Users\\user\\PycharmProjects\\PlotlyExample'],
binaries=[],
datas=[('C:\\Users\\user\\PycharmProjects\\PlotlyExample\\venv\\Lib\\site-packages\\plotly\\', 'plotly'),
('C:\\Users\\user\\PycharmProjects\\PlotlyExample\\venv\\Lib\\site-packages\\kaleido\\', 'kaleido'),
('C:\\Users\\user\\PycharmProjects\\PlotlyExample\\venv\\Lib\\site-packages\\pptx\\', 'pptx'),],
hiddenimports=['pandas','numpy','plotly','pptx'],
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,
[],
exclude_binaries=True,
name='main',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
console=True )
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True,
upx_exclude=[],
name='main')
添加回答
舉報