Tkinter 如何手动将PIL模块添加到pyinstaller exe?

Tkinter 如何手动将PIL模块添加到pyinstaller exe?,tkinter,python-imaging-library,pyinstaller,modulenotfounderror,Tkinter,Python Imaging Library,Pyinstaller,Modulenotfounderror,我正在使用pyinstaller创建一个独立的exe文件,但在尝试运行它时出现“modulenotfound”错误。它无法定位PIL模块,即使它与我的所有其他模块位于同一个“站点包”文件夹中。我如何告诉它PIL模块在哪里 在使用pyinstaller时,我在cmd行中尝试了以下标志,但均无效: --hidden-import=Pillow --hidden-import='PIL' --hidden-import='Pillow' 我的脚本使用以下与PIL模块相关的代码行: from

我正在使用pyinstaller创建一个独立的exe文件,但在尝试运行它时出现“modulenotfound”错误。它无法定位PIL模块,即使它与我的所有其他模块位于同一个“站点包”文件夹中。我如何告诉它PIL模块在哪里

在使用pyinstaller时,我在cmd行中尝试了以下标志,但均无效:

--hidden-import=Pillow
--hidden-import='PIL'
--hidden-import='Pillow'
我的脚本使用以下与PIL模块相关的代码行:

    from PIL import Image, ImageTk

脚本中的一切都很好,只有当我使用pyinstaller时,我才有问题。

我找到了一个解决方案:我必须在PyCharm终端中安装pyinstaller,然后我必须在PyCharm终端中运行pyinstaller,并使用

pyinstaller --onefile -w "foo.py"

我以前在PyCharm外的文件目录中运行cmd并在那里运行pyinstaller,但在PyCharm内运行pyinstaller是有效的。

我只是从驱动器中的Python文件夹复制了
PIL
的库文件夹,并将其移动到与
.py
文件相同的文件夹中,然后我用
--hidden import=PIL
行运行cmd,它可以正常工作,只需记住将可执行文件放在代码行中的同一目录中,如果它不在同一目录中,则可能无法运行。

试试
--hidden import PIL
。顺便问一下,您是否已将PyInstaller升级到最新版本(4.0)
PIL
(Pillow)自动包含在我的PyInstaller 4.0和Python 3.8.5的Windows 7下。我正在运行PyInstaller 4.0、Python 3.8.3和Windows 10。我尝试了
--hidden import PIL
,但它不起作用,仍然给我modulenotfound错误这是因为pycharm使用虚拟环境