importerror: no module named filedialog - after pyinstaller

  • Last Update :
  • Techknowledgy :

Edit: I have copied the traceback out. There may be a mistake as I had to type it up from a screenshot because it only flashes up.

Traceback (most recent call last):
File "<string>", line 14, in <module>
      File "C:\Users\user\desktop\PyInstaller-2.1\PyInstaller\loader\pyi_importers.py", line 270, in load_module
      exec(bytecode, module.__dict__)
      File "C:\Users\user\desktop\PyInstaller-2.1\my_program\build\my_program\out00-PYZ.pyz\matplotlib.pyplot", line 108, in <module>
         File "C:\Users\user\desktop\PyInstaller-2.1\my_program\build\my_program\out00-PYZ.pyz\matplotlib.backends", line 32, in pylab_setup
         File "C:\Users\user\desktop\PyInstaller-2.1\PyInstaller\loader\pyi_importers.py", line 270, in load_module
         exec(bytecode, module.__dict__)
         File "C:\Users\user\desktop\PyInstaller-2.1\my_program\build\my_program\out00-PYZ.pyz\matplotlib.backends.backend_tkagg", line 7, in <module>
            File "C:\Users\user\desktop\PyInstaller-2.1\my_program\build\my_program\out00-PYZ.pyz\six", line 194, in load_module
            File "C:\Users\user\desktop\PyInstaller-2.1\my_program\build\my_program\out00-PYZ.pyz\six", line 108, in _resolve
            File "C:\Users\user\desktop\PyInstaller-2.1\my_program\build\my_program\out00-PYZ.pyz\six", line 779, in _import_module
            ImportError: No module named FileDialog

Below are the imports that I have in my code:

import Tkinter
from tkFileDialog
import askopenfilename
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.mlab as mlab
from matplotlib.backends.backend_tkagg
import FigureCanvasTkAgg
import subprocess
from PIL
import Image, ImageTk
import os

Suggestion : 2

According to this question adding import FileDialog solves the problem. Matplotlib seems to need this. However, I've used Pyinstaller on a script of mine also importing matplotlib and it gives no such error. So I don't know what exacly is the problem here., 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 . Just change the following line: The problem were some runtime dependencies of matplotlib. , 5 days ago Feb 03, 2021  · After redirecting stdout and stderr to a file I could see that I missed the libraries Tkinter and FileDialog. Adding two imports at the top of the main solved this problem. Had a similar problem with no module named FileDialog. Discovered that with version 3.2, I could use . pyinstaller --hidden-import FileDialog ... instead of modifying my ... ,Does anyone know whats causing this/what the fix is? I presume the error is the importation of tkFileDialog?


Traceback (most recent call last): File "<string>", line 14, in <module> File "C:\Users\user\desktop\PyInstaller-2.1\PyInstaller\loader\pyi_importers.py", line 270, in load_module exec(bytecode, module.__dict__) File "C:\Users\user\desktop\PyInstaller-2.1\my_program\build\my_program\out00-PYZ.pyz\matplotlib.pyplot", line 108, in <module> File "C:\Users\user\desktop\PyInstaller-2.1\my_program\build\my_program\out00-PYZ.pyz\matplotlib.backends", line 32, in pylab_setup File "C:\Users\user\desktop\PyInstaller-2.1\PyInstaller\loader\pyi_importers.py", line 270, in load_module exec(bytecode, module.__dict__) File "C:\Users\user\desktop\PyInstaller-2.1\my_program\build\my_program\out00-PYZ.pyz\matplotlib.backends.backend_tkagg", line 7, in <module> File "C:\Users\user\desktop\PyInstaller-2.1\my_program\build\my_program\out00-PYZ.pyz\six", line 194, in load_module File "C:\Users\user\desktop\PyInstaller-2.1\my_program\build\my_program\out00-PYZ.pyz\six", line 108, in _resolve File "C:\Users\user\desktop\PyInstaller-2.1\my_program\build\my_program\out00-PYZ.pyz\six", line 779, in _import_module ImportError: No module named FileDialog
Traceback (most recent call last): File "<string>", line 14, in <module>File "C:\Users\user\desktop\PyInstaller-2.1\PyInstaller\loader\pyi_importers.py", line 270, in load_module exec(bytecode, module.__dict__) File "C:\Users\user\desktop\PyInstaller-2.1\my_program\build\my_program\out00-PYZ.pyz\matplotlib.pyplot", line 108, in <module>File "C:\Users\user\desktop\PyInstaller-2.1\my_program\build\my_program\out00-PYZ.pyz\matplotlib.backends", line 32, in pylab_setup File "C:\Users\user\desktop\PyInstaller-2.1\PyInstaller\loader\pyi_importers.py", line 270, in load_module exec(bytecode, module.__dict__) File "C:\Users\user\desktop\PyInstaller-2.1\my_program\build\my_program\out00-PYZ.pyz\matplotlib.backends.backend_tkagg", line 7, in <module>File "C:\Users\user\desktop\PyInstaller-2.1\my_program\build\my_program\out00-PYZ.pyz\six", line 194, in load_module File "C:\Users\user\desktop\PyInstaller-2.1\my_program\build\my_program\out00-PYZ.pyz\six", line 108, in _resolve File "C:\Users\user\desktop\PyInstaller-2.1\my_program\build\my_program\out00-PYZ.pyz\six", line 779, in _import_module ImportError: No module named FileDialog
import Tkinter from tkFileDialog
import askopenfilename
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.mlab as mlab from matplotlib.backends.backend_tkagg
import FigureCanvasTkAgg
import subprocess from PIL
import Image, ImageTk
import os

Suggestion : 3

I wrote a program which I tried to turn into an executable using PyInstaller. It looks like Pyinstaller finished without any errors and I ended up with the application in / dist / my_program. However, when I try to run this application, the console window blinks for a second with a trace:,Edit2: The program works fine when I run it in my interpreter (Spyder), but when I packaged it with PyInstaller, the resulting application gives this error.,As per this question, the addition import FileDialog solves the problem. Matplotlib seems to need this. However, I used Pyinstaller on a script that also imported matplotlib and does not give such an error. So I don't know what the problem is, the problem is here.,Does anyone know what is causing this / what the fix is? I'm guessing the error is the import of tkFileDialog?

Edit: I copied the traceback. There may have been an error as I had to type it from the screenshot because it only flashes.

Traceback (most recent call last):
File "<string>", line 14, in <module>
File "C:\Users\user\desktop\PyInstaller-2.1\PyInstaller\loader\pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "C:\Users\user\desktop\PyInstaller-2.1\my_program\build\my_program\out00-PYZ.pyz\matplotlib.pyplot", line 108, in <module>
File "C:\Users\user\desktop\PyInstaller-2.1\my_program\build\my_program\out00-PYZ.pyz\matplotlib.backends", line 32, in pylab_setup
File "C:\Users\user\desktop\PyInstaller-2.1\PyInstaller\loader\pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "C:\Users\user\desktop\PyInstaller-2.1\my_program\build\my_program\out00-PYZ.pyz\matplotlib.backends.backend_tkagg", line 7, in <module>
File "C:\Users\user\desktop\PyInstaller-2.1\my_program\build\my_program\out00-PYZ.pyz\six", line 194, in load_module
File "C:\Users\user\desktop\PyInstaller-2.1\my_program\build\my_program\out00-PYZ.pyz\six", line 108, in _resolve
File "C:\Users\user\desktop\PyInstaller-2.1\my_program\build\my_program\out00-PYZ.pyz\six", line 779, in _import_module
ImportError: No module named FileDialog

      
        
        
        
          (adsbygoogle = window.adsbygoogle || []).push({});
        
      
    

The following are the imports I have in my code:

import Tkinter
from tkFileDialog
import askopenfilename
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.mlab as mlab
from matplotlib.backends.backend_tkagg
import FigureCanvasTkAgg
import subprocess
from PIL
import Image, ImageTk
import os

   (adsbygoogle = window.adsbygoogle || []).push({});

Suggestion : 4

Had a similar problem with no module named FileDialog. Discovered that with version 3.2, I could use,I try to compile a Python project under Windows 7 using PyInstaller. The project works fine, there are no issues, however when I try to compile it the result doesn’t work. Though I get no warnings during compilation there are many in the warnmain.txt file in the build directory: warnmain.txt,I had similar problem with PySimpleGUI. The problem was, pyinstaller was installed in different directory. SOLUTION (solved for me) : just install pyinstaller in the same directory in which the file is present (that to be converted to exe),The problem were some runtime dependencies of matplotlib. So the compiling was fine while running the program threw some errors. Because the terminal closed itself immediately I didn’t realize that. After redirecting stdout and stderr to a file I could see that I missed the libraries Tkinter and FileDialog. Adding two imports at the top of the main solved this problem.

However I was able to compile a simple script which uses numpy succesfully:

import sys
from PyQt4
import QtGui, QtCore
import numpy as np

class MainWindow(QtGui.QMainWindow):
   def __init__(self):
   QtGui.QMainWindow.__init__(self)

self.pb = QtGui.QPushButton(str(np.pi), self)

app = QtGui.QApplication(sys.argv)
main = MainWindow()
main.show()
sys.exit(app.exec_())
2._
import numpy as np
import matplotlib.pyplot as ppl
from matplotlib.backends.backend_qt4agg
import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt4agg
import NavigationToolbar2QTAgg as NavigationToolbar
from PyQt4
import QtGui, QtCore
import json
import sys
import numpy # added this one later
import matplotlib # added this one later

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

hiddenimports = [],
2._
hiddenimports = ["Tkinter", "FileDialog"],

If the matter is that you don’t need Tkinter and friends because you are using PyQt4, then it might be best to avoid loading Tkinter etc altogether. Look into /etc/matplotlibrc and change the defaults to PyQt4, see the ‘modified’ lines below:

# # # # CONFIGURATION BEGINS HERE

# The
default backend;
one of GTK GTKAgg GTKCairo GTK3Agg GTK3Cairo
# CocoaAgg MacOSX Qt4Agg Qt5Agg TkAgg WX WXAgg Agg Cairo GDK PS PDF SVG
# Template.
# You can also deploy your own backend outside of matplotlib by
# referring to the module name(which must be in the PYTHONPATH) as
# 'module://my_backend'.

#modified
#backend: TkAgg
backend: Qt4Agg

# If you are using the Qt4Agg backend, you can choose here
# to use the PyQt4 bindings or the newer PySide bindings to
# the underlying Qt4 toolkit.

#modified
#backend.qt4: PyQt4 # PyQt4 | PySide
backend.qt4: PyQt4 # PyQt4 | PySide

Upgrading to 3.1 and deleting all build files helped.

pip install--upgrade pyinstaller

Suggestion : 5

One solution is to modify the hook file anycodings_python-2.7 hook-PIL.py located in anycodings_python-2.7 YourPythonFolder\Lib\site-packages\PyInstaller\hooks anycodings_python-2.7 by removing the modname_tkinter from anycodings_python-2.7 excludedimports.,Otherwise, Py2exe is also an option for anycodings_python-2.7 creating a .exe file, and i have used it anycodings_python-2.7 plenty of times with tkinter with no anycodings_python-2.7 issues.,Check anycodings_python-2.7 https://github.com/pyinstaller/pyinstaller/issues/1584. anycodings_python-2.7 There is an issue with the PIL hook, anycodings_python-2.7 which excludes the tkinter module. ,quote from issue 1877 "It looks like the anycodings_python-2.7 hook-_tkinter.py is not able to handle anycodings_python-2.7 custom compiled Tk." Possible anycodings_python-2.7 workaround: "Thanks, after installed anycodings_python-2.7 tkinter, tix, tcl-devel and tk-devel anycodings_python-2.7 using yum installation, It's now work anycodings_python-2.7 fine. "

I've built a Python (2.7) app that uses anycodings_pyinstaller Tkinter and am trying to build a Windows7 anycodings_pyinstaller .exe using Pyinstaller (3.2). The app works anycodings_pyinstaller find in windows is I run it as python anycodings_pyinstaller myapp.py, but once compiled into a anycodings_pyinstaller pyinstaller distributable, I get this error anycodings_pyinstaller message:

ImportError: No module named Tkinter

Just to be sure, the top of myapp.py anycodings_pyinstaller contains:

from copy
import deepcopy
import cPickle as pickle
import Tkinter as tk
from PIL
import ImageTk

Or just change the order of the import anycodings_python-2.7 statements in your code. Do:

from PIL
import ImageTk
import Tkinter as tk

Suggestion : 6

initialfile: initially selected item (just the name, not the full path),File browser for Tkinter, alternative to tkinter.filedialog in linux with GTK bookmarks support.,tkfilebrowser is an alternative to tkinter.filedialog that allows the user to select files or directories. The GUI is written with tkinter but the look is closer to GTK and the application uses GTK bookmarks (the one displayed in nautilus or thunar for instance). This filebrowser supports new directory creation and filtype filtering.,This module contains a general FileBrowser class which implements the filebrowser and the following functions, similar to the one in filedialog:

$ sudo add - apt - repository ppa: j - 4321 - i / ppa
$ sudo apt - get update
$ sudo apt - get install python(3) - tkfilebrowser
$ pip install tkfilebrowser
try:
import tkinter as tk
import tkinter.ttk as ttk
from tkinter
import filedialog
except ImportError:
   import Tkinter as tk
import ttk
import tkFileDialog as filedialog
from tkfilebrowser
import askopendirname, askopenfilenames, asksaveasfilename

root = tk.Tk()

style = ttk.Style(root)
style.theme_use("clam")

def c_open_file_old():
   rep = filedialog.askopenfilenames(parent = root, initialdir = '/', initialfile = 'tmp',
      filetypes = [("PNG", "*.png"), ("JPEG", "*.jpg"), ("All files", "*")])
print(rep)

def c_open_dir_old():
   rep = filedialog.askdirectory(parent = root, initialdir = '/tmp')
print(rep)

def c_save_old():
   rep = filedialog.asksaveasfilename(parent = root, defaultextension = ".png", initialdir = '/tmp', initialfile = 'image.png',
      filetypes = [("PNG", "*.png"), ("JPEG", "*.jpg"), ("All files", "*")])
print(rep)

def c_open_file():
   rep = askopenfilenames(parent = root, initialdir = '/', initialfile = 'tmp',
      filetypes = [("Pictures", "*.png|*.jpg|*.JPG"), ("All files", "*")])
print(rep)

def c_open_dir():
   rep = askopendirname(parent = root, initialdir = '/', initialfile = 'tmp')
print(rep)

def c_save():
   rep = asksaveasfilename(parent = root, defaultext = ".png", initialdir = '/tmp', initialfile = 'image.png',
      filetypes = [("Pictures", "*.png|*.jpg|*.JPG"), ("All files", "*")])
print(rep)

ttk.Label(root, text = 'Default dialogs').grid(row = 0, column = 0, padx = 4, pady = 4, sticky = 'ew')
ttk.Label(root, text = 'tkfilebrowser dialogs').grid(row = 0, column = 1, padx = 4, pady = 4, sticky = 'ew')
ttk.Button(root, text = "Open files", command = c_open_file_old).grid(row = 1, column = 0, padx = 4, pady = 4, sticky = 'ew')
ttk.Button(root, text = "Open folder", command = c_open_dir_old).grid(row = 2, column = 0, padx = 4, pady = 4, sticky = 'ew')
ttk.Button(root, text = "Save file", command = c_save_old).grid(row = 3, column = 0, padx = 4, pady = 4, sticky = 'ew')
ttk.Button(root, text = "Open files", command = c_open_file).grid(row = 1, column = 1, padx = 4, pady = 4, sticky = 'ew')
ttk.Button(root, text = "Open folder", command = c_open_dir).grid(row = 2, column = 1, padx = 4, pady = 4, sticky = 'ew')
ttk.Button(root, text = "Save file", command = c_save).grid(row = 3, column = 1, padx = 4, pady = 4, sticky = 'ew')

root.mainloop()