简体   繁体   English

ImportError:在pyInstaller之后没有名为“ tkinter”的模块

[英]ImportError: No module named 'tkinter' after pyInstaller

I want to do an executable, but ervery time I run the .exe it writes ImportError: No module named 'tkinter' , and all I read on Stackowerflow do not help me ! 我想执行一个可执行文件,但是每次我运行.exe时,它都会写ImportError: No module named 'tkinter' tkinter ImportError: No module named 'tkinter' ,而我在Stackowerflow上阅读的所有内容都对我没有帮助!

My python program is simple (ODE solver) and requests only : 我的python程序很简单(ODE求解器),仅请求:

from math import*
from pylab import*
import numpy as np

import matplotlib
import numpy as np
import matplotlib.pyplot as plt

I paste a copy of my prog.py into the C:\\Python\\Scripts folder where pyInstaller is. 我将prog.py的副本粘贴到prog.pyC:\\Python\\Scripts文件夹中。 I compute the command line pyinstaller -F eulersolver.py , this creates a prog.exe in the dist folder. 我计算了命令行pyinstaller -F eulersolver.py ,这在dist文件夹中创建了一个prog.exe When I run this code I have 当我运行此代码时,

ImportError: No module named 'tkinter'
Failed to execute script prog

But my program do not use this module... do you have any proposition or help for me ? 但是我的程序不使用此模块...您对我有什么建议或帮助吗?

OS : Windows64 作业系统: Windows64

Python : 3.5 for Win64 适用于Win64的Python: 3.5

Note : I already unistall/install python 3 times today (after reading documentation on this webside and abroad). 注意:我今天已经卸载/安装python 3次了(在阅读本网站和国外的文档之后)。

Note 2 : I use Python only for scientific issues. 注2:我仅将Python用于科学问题。 I am no computer scientist, so be kind to me when explaining computer stuff :S 我不是计算机科学家,所以在解释计算机内容时对我友善:S

最终适用于pyinstaller -F --hidden-import=tkinter --hidden-import=tkinter.filedialog prog.py感谢!

您应该使用隐藏导入
pyinstaller eulersolver.py --hidden-import=tkinter -y

The problem is that pyinstaller won't see second level imports . 问题是pyinstaller无法看到二级导入 So if you import module A , pyinstaller sees this. 因此,如果导入模块A ,则pyinstaller会看到此信息。 But any additional module that is imported in A will not be seen. 但是将看不到A中导入的任何其他模块。

There is no need to change anything in your python scripts. 无需更改python脚本中的任何内容。 You can directly add the missing imports to the spec file ( prog.spec in your case). 您可以将缺少的导入内容直接添加到spec文件中 (在您的情况下为prog.spec )。 Just change the following line: 只需更改以下行:

hiddenimports=[],

to

hiddenimports=["tkinter"],

After that run pyinstaller prog.spec to create the prog.exe . 之后,运行pyinstaller prog.spec创建prog.exe

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM