4

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

user1251007
  • 15,891
  • 14
  • 50
  • 76
John
  • 303
  • 4
  • 13
  • EDIT (because I cannot edit my own post -_-) : the command line is actually `pyinstaller -F prog.py` – John Dec 19 '16 at 18:41
  • `matplotlib` use `tkinter` to display window with plot. – furas Dec 19 '16 at 21:03
  • try to `import tkinter` maybe then it assign tkinter module too. Or read how to set config before you run `pyinstaller`. `tkinter` uses external `dll` with language `tcl` and its gui `tk` so maybe you have to manually add to config information about `tcl.dll` and `tk.dll` (I don't use Windows so I don't know if it is `tcl.dll` and `tk.dll`) – furas Dec 19 '16 at 21:06
  • Did that, but the same result when importing tkinter :( – John Dec 20 '16 at 13:10
  • Possible duplicate of [PyInstaller - no module named](http://stackoverflow.com/questions/25733467/pyinstaller-no-module-named) – user1251007 Jan 25 '17 at 21:54

3 Answers3

4

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

John
  • 303
  • 4
  • 13
2

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

Arduino_Sentinel
  • 819
  • 11
  • 21
2

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.

user1251007
  • 15,891
  • 14
  • 50
  • 76