我的 python 脚本的 Exe 不 运行 因为它不识别模块 PIL

Exe for my python script does not run because it does not recognize the module PIL

我已经完成了一个python项目,想制作一个exe文件以便于访问。创建所述 exe 后,我尝试 运行 它但错误提示“没有名为 'PIL' 的模块”。从解释器执行脚本时一切正常。

我试过:

如果需要更多详细信息,我会提供。

您需要在设置中包含库的路径。示例(来自 docs):

block_cipher = None
a = Analysis(['minimal.py'],
     pathex=['/Developer/PItests/minimal'],
     binaries=None,
     datas=None,
     hiddenimports=[],
     hookspath=None,
     runtime_hooks=None,
     excludes=None,
     cipher=block_cipher)

您需要在 pathex 参数中包含模块的路径。如果这仍然不能解决您的问题,则 pyinstaller 无法识别您的导入。您可以在 hiddenimports 参数中明确设置它。