John
John

Reputation: 303

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 !

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

Upvotes: 4

Views: 9420

Answers (3)

John
John

Reputation: 303

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

Upvotes: 4

user1251007
user1251007

Reputation: 16781

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.

Upvotes: 2

Arduino_Sentinel
Arduino_Sentinel

Reputation: 819

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

Upvotes: 2

Related Questions