【问题标题】:Python executable created with PyInstaller doesn't run使用 PyInstaller 创建的 Python 可执行文件无法运行
【发布时间】:2016-12-04 23:16:17
【问题描述】:

我有一个简单的脚本来绘制 ROC 曲线(使用 sklearnmatplotlib)。我使用PyInstaller 从这个脚本创建一个可执行文件。脚本本身运行良好,但可执行文件给了我这个错误:

没有名为“tkinter”的模块

我尝试了什么:

1) 重新创建不带 --onefile 标志的可执行文件(以防任何 .dll 丢失)(失败)

2) 在我的脚本中手动导入tkinter(失败)

实际上,当我添加import tkinter 时,错误更改为(以防万一):

没有名为“tkinter.filedialog”的模块

我很困惑。我用了很多次PyInstaller,但这是我第一次遇到这种错误。

【问题讨论】:

    标签: python matplotlib executable pyinstaller


    【解决方案1】:

    编辑.spec 文件并将模块路径放在“pathex”内(在分析中)。您可以使用module.__file__ 发现正确的模块路径。 在你的情况下:

    >>> import tkinter.filedialog
    >>> tkinter.filedialog.__file__
    '/usr/lib/python3.5/tkinter/filedialog.py'
    

    .spec 文件:

     a = Analysis(['main.py'],
                     pathex=['/usr/lib/python3.5/tkinter/'],
                     binaries=None,
                     datas=None,
                     hiddenimports=[],
                     hookspath=[],
                     runtime_hooks=[],
                     excludes=[],
                     win_no_prefer_redirects=False,
                     win_private_assemblies=False,
                     cipher=block_cipher)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-12-10
      • 2016-12-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多