When using modules under six.moves.urllib, PyInstaller does not find the final module. six does some more magic for everything under six.moves.urllib, which isn't captured by the simple logic in the hook.
Simplest test case:
from six.moves.urllib import robotparser
print(robotparser.RobotFileParser().parse(""))
This program should print "None", when packaged with PyInstaller, it fails with:
Traceback (most recent call last):
File "foo.py", line 5, in <module>
print(robotparser.RobotFileParser().parse(""))
File "site-packages/six.py", line 92, in __get__
File "site-packages/six.py", line 160, in _resolve
File "site-packages/six.py", line 82, in _import_module
ImportError: No module named 'urllib.robotparser'
I took a look at the hook, and I think it is probably the better idea to really parse six._importer.known_modules and somehow get the "real" module names from those _LazyModule classes...
I am having a similar, I think related issue with 3.2. When I try to import matplotlib.pylot (matplotlib version = 1.5.1) in my code, it eventually tries to import matplotlib.backends.backend_tkagg, which has the following import statements:
from matplotlib.externals.six.moves import tkinter as Tk
from matplotlib.externals.six.moves import tkinter_filedialog as FileDialog
The first one apparently works, but the second gives me this exception:
Traceback (most recent call last):
File "DHDParser.py", line 35, in <module>
File "c:\users\462974\appdata\local\temp\pip-build-ik60kz\pyinstaller\PyInstaller\loader\pyimod03_importers.py", line 389, in load_module
File "lib\site-packages\matplotlib\pyplot.py", line 114, in <module>
File "lib\site-packages\matplotlib\backends\__init__.py", line 32, in pylab_setup
File "c:\users\462974\appdata\local\temp\pip-build-ik60kz\pyinstaller\PyInstaller\loader\pyimod03_importers.py", line 389, in load_module
File "lib\site-packages\matplotlib\backends\backend_tkagg.py", line 7, in <module>
File "lib\site-packages\matplotlib\externals\six.py", line 199, in load_module
File "lib\site-packages\matplotlib\externals\six.py", line 113, in _resolve
File "lib\site-packages\matplotlib\externals\six.py", line 80, in _import_module
ImportError: No module named FileDialog
This only happens in the built (onedir) version of my program, not when running from source. I don't understand why the first import statement from matplotlib.externals.six.moves works but not the second, and why it's looking for a module named "FileDialog" when that's just the alias being assigned to the imported module and not the module name itself.
I'm having exactly the same problem as @dpitch40 . Any news on that or suggestion for a workaround?
I'm having this exact problem on CentOS-7 Linux but NOT in Windows 10 with exactly the same Python code. Why has this issue languished for 3 years? If it doesn't get fixed I may have to abandon pyinstaller!
Most helpful comment
I am having a similar, I think related issue with 3.2. When I try to import matplotlib.pylot (matplotlib version = 1.5.1) in my code, it eventually tries to import matplotlib.backends.backend_tkagg, which has the following import statements:
The first one apparently works, but the second gives me this exception:
This only happens in the built (onedir) version of my program, not when running from source. I don't understand why the first import statement from matplotlib.externals.six.moves works but not the second, and why it's looking for a module named "FileDialog" when that's just the alias being assigned to the imported module and not the module name itself.