Pyinstaller for Windows can't find custom module

1,534 views
Skip to first unread message

Paul Fishback

unread,
May 13, 2022, 11:45:56 AM5/13/22
to PyInstaller
I have a script that utilizes a custom module named "utils." At the start of the main script, I import functions from scripts contained within "utils," such as "from utils.general import helper."

I've been trying to add my own module as a hidden import in my spec file, and while running pyinstaller doesn't produce any errors, double clicking on the executable leads to ModuleNotFoundError: No module named 'utils'

Here's my spec file, where I've tried adding the module as a hidden import as well as in pathex:

block_cipher = None
a = Analysis(['My Application.py'],
             pathex=['C:\\Users\\utils']
,
             binaries=[],
             datas=datas,
             hiddenimports=['C:\\Users\\utils','PIL'],
             hookspath=[],
             hooksconfig={},
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)

exe = EXE(pyz,
          a.scripts,
          a.binaries,
          a.zipfiles,
          a.datas,  
          [],
          name='My Application',
          debug=False,
          bootloader_ignore_signals=False,
          strip=False,
          upx=True,
          upx_exclude=[],
          runtime_tmpdir=None,
          console=False,
          disable_windowed_traceback=False,
          target_arch=None,
          codesign_identity=None,
      icon='my_icon.ico',
      version='file_version_info.txt',
          entitlements_file=None )

app = BUNDLE(name='My Application.exe',bundle_identifier=None,
info_plist={
        'CFBundleIdentifier': 'My Application',
        'CFBundleName': 'My Application',
        'CFBundleIconFile': 'my_icon.ico',
        'CFBundleDisplayName': 'My Application',
        'CFBundleShortVersionString':'v 0.1',
        'LSEnvironment': {
            'LANG': 'de_DE.UTF-8',
            'LC_CTYPE': 'de_DE.UTF-8'
        }})


bwoodsend

unread,
May 14, 2022, 3:06:33 AM5/14/22
to PyInstaller

It’s the parent directory of your custom package that needs adding to sys.path (controlled via pathex). pathex=[‘C:\Users’], should do it. You’ll probably need to rebuild adding the —clean option (or you can just delete the build folder). That said, using pathex at all is a symptom of poor package design. Turn your code into a pip-installable Python package with a setup.py and you’ll never have issues like this again.

Chris Barker - NOAA Federal

unread,
May 14, 2022, 3:06:40 AM5/14/22
to pyins...@googlegroups.com
Where/how do you install your utils module?

I highly recommend that you make a package out of it and install it.

That’s a good idea for all sorts of reasons, and will likely make PyInstaller happier.

-CHB

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

On May 13, 2022, at 8:46 AM, Paul Fishback <fishba...@gmail.com> wrote:

I have a script that utilizes a custom module named "utils." At the start of the main script, I import functions from scripts contained within "utils," such as "from utils.general import helper."
--
You received this message because you are subscribed to the Google Groups "PyInstaller" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyinstaller...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyinstaller/e28ebb38-5c58-407e-b955-2f2f74536b13n%40googlegroups.com.

Paul Fishback

unread,
May 18, 2022, 11:42:06 AM5/18/22
to PyInstaller
Thank you bwoodsend and Christoper for your responses. I'll look into making a package that's pip-installable. More fun stuff to learn!

Paul 

Reply all
Reply to author
Forward
0 new messages