'pyinstaller cannot see configparser

I am using configparser in a python application

When I run the application

python main.py

it works. However if I use pyinstall to create a windows exe, the exe fails with the message

no module named 'configparser'

however as the screen shot shows, configparser does exist

What is going on here?

NB I do NOT get the error if I remove __init__.py from the directory

enter image description here

[More info]

This seems to be a 'sys.path' issue. If I copy configparser.py into my application directory, the problem moves on to another module that I'm calling

Should I change my pyinstaller spec file?

# -*- mode: python -*-
a = Analysis(['main.py'],
             hiddenimports=[],
             hookspath=None,
             runtime_hooks=None)
a.datas = list({tuple(map(str.upper, t)) for t in a.datas})
pyz = PYZ(a.pure)
exe = EXE(pyz,
          a.scripts,
          a.binaries,
          a.zipfiles,
          a.datas,
          name='test_imports.exe',
          debug=False,
          strip=None,
          upx=True,
          console=True)


Solution 1:[1]

I also had this issue. In my case, it was a hidden import and was fixed with the --hidden-import option.

$ pyinstaller my_script.py --hidden-import=configparser

Solution 2:[2]

Fixed this by removing __init__.py from root directory

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ian Stewart
Solution 2 Psionman