2

Assume that this is my file structure:

main.py
modules
  |--> feature1.py
  |--> feature2.py
  |--> feature3.py

My main.py code is as following:

from modules.feature1 import Awesomefeature
...

I used the following spec-file for PyInstaller:

# -*- mode: python -*-

block_cipher = None


a = Analysis(['main.py'],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          a.binaries,
          a.zipfiles,
          a.datas,
          name='main',
          debug=False,
          strip=False,
          upx=False,
          runtime_tmpdir=None,
          console=True , icon='icon.ico')

Unfortunately I get the following message after I compile my code to a windows executable and execute this (main.exe file):

ModuleNotFoundError: no module named 'modules'

Is it completely impossible to have subfolders with pythoncode in it while using pyinstaller?

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
user5989986
  • 73
  • 2
  • 9

1 Answers1

1

Try adding the pathex list to the spec file with a path to the root project directory.

a = Analysis(['main.py']),
             pathex=['C:/Users/<user>/Path to the root directory'],
             # rest of spec file

Sometimes you need to add module locations to the pathex list. This is a list of paths that pyinstaller will search first.

MalloyDelacroix
  • 2,193
  • 1
  • 13
  • 17