[英]Python executable created with PyInstaller doesn't run
I have a simple script in order to plot a ROC curve (using sklearn
and matplotlib
). 我有一个简单的脚本来绘制ROC曲线(使用
sklearn
和matplotlib
)。 I used PyInstaller
to create an executable from this script. 我使用
PyInstaller
从此脚本创建可执行文件。 The script itself runs and works perfectly but the executable gives me this error: 脚本本身可以正常运行,但是可执行文件给我这个错误:
No module named 'tkinter'
没有名为“ tkinter”的模块
What I tried: 我试过的
1) Re-create the executable without the --onefile
flag (in case any .dll was missing) (FAILED) 1)重新创建不带
--onefile
标志的可执行文件(以防丢失任何.dll)(失败)
2) Manually import tkinter
inside my script (FAILED) 2)在脚本中手动导入
tkinter
(失败)
Actually when I added import tkinter
the error changed to (in case it matters): 实际上,当我添加
import tkinter
,错误更改为(以防万一):
No module named 'tkinter.filedialog'
没有名为“ tkinter.filedialog”的模块
I am confused. 我很困惑。 I used
PyInstaller
many times but it's the first time I encounter this kind of error. 我多次使用
PyInstaller
,但这是我第一次遇到这种错误。
Edit the .spec file and put the path to the module inside 'pathex' (on Analysis). 编辑.spec文件,并将模块的路径放入“ pathex”(在Analysis中)中。 You can discover the correct module path using
module.__file__
. 您可以使用
module.__file__
找到正确的模块路径。 In your case: 在您的情况下:
>>> import tkinter.filedialog
>>> tkinter.filedialog.__file__
'/usr/lib/python3.5/tkinter/filedialog.py'
On .spec file: 在.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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.