简体   繁体   English

用PyInstaller创建的Python可执行文件无法运行

[英]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曲线(使用sklearnmatplotlib )。 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.

相关问题 pyinstaller可执行文件未在Ubuntu 18.04.1中运行 - pyinstaller executable doesn't run in Ubuntu 18.04.1 使用PyInstaller创建的桌面应用无法运行 - Desktop app created with PyInstaller doesn't run 使用 pyinstaller 创建的 Python 可执行文件将不再与依赖包一起运行 - Python executable created using pyinstaller will no longer run with dependant packages PyInstaller:单文件可执行文件不运行 - PyInstaller: Single-file executable doesn't run pyinstaller可执行文件隐藏时不运行进程 - Pyinstaller executable doesn't run processes when hidden 带有Python 3的Pyinstaller无法正常运行 - Pyinstaller with Python 3 doesn't run as it should PyInstaller将我的python脚本构建为可执行文件,但是不起作用 - PyInstaller built my python scripts to executable file, but it doesn't work python PyInstaller创建的可执行文件无法运行exe错误:找不到Temp \\\\ _ MEI175682(数据文件) - python PyInstaller created executable failed to run the exe Error: cannot find Temp\\_MEI175682 (data file) 使用 Pyinstaller 编译后,带有 Pyscreenshot 脚本的 Python Tkinter 不运行 - Python Tkinter with Pyscreenshot script doesn't run after compiling with Pyinstaller 使用pyinstaller使其成为可执行文件后,无法在Python中移动文件 - Moving files in Python doesn't work once made executable using pyinstaller
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM