ImportError: No module named 'tkinter' after pyInstaller

8k Views Asked by At

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 !

My python program is simple (ODE solver) and requests only :

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. I compute the command line pyinstaller -F eulersolver.py, this creates a prog.exe in the dist folder. 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

Python : 3.5 for Win64

Note : I already unistall/install python 3 times today (after reading documentation on this webside and abroad).

Note 2 : I use Python only for scientific issues. I am no computer scientist, so be kind to me when explaining computer stuff :S

3

There are 3 best solutions below

0
On BEST ANSWER

You should use hidden import
pyinstaller eulersolver.py --hidden-import=tkinter -y

0
On

FINALLY WORKED FOR pyinstaller -F --hidden-import=tkinter --hidden-import=tkinter.filedialog prog.py Thanks a lot !!!

0
On

The problem is that pyinstaller won't see second level imports. So if you import module A, pyinstaller sees this. But any additional module that is imported in A will not be seen.

There is no need to change anything in your python scripts. You can directly add the missing imports to the spec file (prog.spec in your case). Just change the following line:

hiddenimports=[],

to

hiddenimports=["tkinter"],

After that run pyinstaller prog.spec to create the prog.exe.