Mar*_*ino 4 python pyinstaller plotly plotly-dash
我正在尝试创建一个 .exe 文件来运行使用 Plotly Dash 创建的 python 仪表板。一旦我使用 PyInstaller 创建文件并尝试运行它,我就会收到此错误:
Traceback (most recent call last):
File "app.py", line 2, in <module>
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "/Users/mohamedmartino/opt/anaconda3/lib/python3.7/site-packages/PyInstaller/loader/pyimod03_importers.py", line 623, in exec_module
exec(bytecode, module.__dict__)
File "site-packages/dash_core_components/__init__.py", line 12, in <module>
FileNotFoundError: [Errno 2] No such file or directory: '/var/folders/np/m30g9mj57h72n68qxc2tq61m0000gn/T/_MEI2yKNs4/dash_core_components/package-info.json'
[85571] Failed to execute script app
Run Code Online (Sandbox Code Playgroud)
我有一些 python 模块和 excel 文件以及一个包含图像和 css 文件的 -asset 文件夹。
看来我们需要修改 .spec 文件(见下面的 sample.spec )。
修改spec文件后,在控制台输入'pyinstaller ***.spec'(好像'--onefile'选项不起作用),然后你就可以从浏览器连接你的dash URL。
#Sample.spec
# -*- mode: python ; coding: utf-8 -*-
#manually add Start to avoid rerusion limit error==>
import sys
sys.setrecursionlimit(5000)
#manually add End<==
block_cipher = None
a = Analysis(['dashtest.py'],
pathex=['C:\\Users\\Owner\\Documents\\python\\Simulatortest\\sandbox'],
binaries=[],
#modified Start==>
datas=[
('C:\\Users\\Owner\\anaconda3\\pkgs\\dash-core-components-1.3.1-py_0\\site-packages\\dash_core_components\\', 'dash_core_components'),
('C:\\Users\\Owner\\anaconda3\\pkgs\\dash-html-components-1.0.1-py_0\\site-packages\\dash_html_components\\', 'dash_html_components'),
('C:\\Users\\Owner\\anaconda3\\pkgs\\dash-renderer-1.1.2-py_0\\site-packages\\dash_renderer\\','dash_renderer'),
],
hiddenimports=['pkg_resources.py2_warn'],
#modified End<==
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='dashtest',
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='dashtest')
Run Code Online (Sandbox Code Playgroud)