File "main.py", line 12, in
File "PyInstaller\loader\pyimod02_importers.py", line 352, in exec_module
File "nicegui_init_.py", line 8, in
File "PyInstaller\loader\pyimod02_importers.py", line 352, in exec_module
File "nicegui\ui.py", line 81, in
File "PyInstaller\loader\pyimod02_importers.py", line 352, in exec_module
File "nicegui\elements\line_plot.py", line 3, in
File "PyInstaller\loader\pyimod02_importers.py", line 352, in exec_module
File "nicegui\elements\pyplot.py", line 4, in
File "PyInstaller\loader\pyimod02_importers.py", line 352, in exec_module
File "matplotlib_init_.py", line 161, in
File "PyInstaller\loader\pyimod02_importers.py", line 352, in exec_module
File "matplotlib\rcsetup.py", line 27, in
File "PyInstaller\loader\pyimod02_importers.py", line 352, in exec_module
File "matplotlib\colors.py", line 56, in
File "PyInstaller\loader\pyimod02_importers.py", line 352, in exec_module
File "matplotlib\scale.py", line 22, in
File "PyInstaller\loader\pyimod02_importers.py", line 352, in exec_module
File "matplotlib\ticker.py", line 138, in
File "PyInstaller\loader\pyimod02_importers.py", line 352, in exec_module
File "matplotlib\transforms.py", line 49, in
ImportError: DLL load failed while importing _path: 找不到指定的模块。
[19164] Failed to execute script 'main' due to unhandled exception!
找到matplotlib\transforms.py指定行
from matplotlib._path import (
affine_transform, count_bboxes_overlapping_bbox, update_path_extents)
在Pycharm中双击进入
文件位于
python_stubs\-1056256661\matplotlib
下
python_stubs文件是一个自动生成的文件,其中包含内置函数的虚拟定义。如果未针对给定版本对内置函数进行硬编码,则PyCharm使用它来推断内置函数的类型。
根据测试,在Pycharm中运行pyinstaller时可能默认调用了python_stubs中的文件,但是封装的时候没有加进来。
删除python_stubs\-1056256661\matplotlib
文件夹或者不用Pycharm打包,直接控制台或者vscode
Pyinstaller 位置:$ProjectFileDir$\venv\Scripts\pyinstaller.exe
实参:-F $FilePath$
工作目录:$FileDir$
import os
import subprocess
from pathlib import Path
import nicegui
cmd = [
'venv\\Scripts\\python.exe',
'-m', 'PyInstaller',
'main.py', # your main file with ui.run()
'--name', 'myapp', # name of your app
'--onefile',
#'--windowed', # prevent console appearing, only use with ui.run(native=True, ...)
'--add-data', f'{Path(nicegui.__file__).parent}{os.pathsep}nicegui'
]
subprocess.call(cmd)
``