0

How to build a python project into a single executable if it has files split in multiple directories?

This is my project structure:

├── main.py
├── main.spec
├── src/
│   ├── GUI/
│   │   ├── RecipyApp.py
│   │   ├── __init__.py
│   ├── __init__.py
│   ├── constants.py
│   ├── exceptions/
│   │   ├── ConfigError.py
│   │   ├── KeywordsNotFound.py
│   │   ├── __init__.py
│   ├── recipies/
│   │   ├── __init__.py
│   │   ├── recipy.py
│   ├── system/
│   │   ├── BaseIndex.py
│   │   ├── InvertedIndex.py
│   │   ├── __init__.py
│   │   ├── config.py
│   │   ├── storage.py
├── tree.py

And when launching it in terminal it works perfectly. However, when building it with pyinstaller like that:

pyinstaller --onefile --windowed main.py

And launching gives an error:

Traceback (most recent call last):
  File "main.py", line 2, in <module>
ModuleNotFoundError: No module named 'src.GUI.RecipyApp'

1 Answer 1

0

In your code structure 'src.GUI.RecipyApp' where RecipyApp is inside src folder
when we run python interpreter it take modules from system path in this case its inside GUI folder not in system path
in your main.spec add pathex property like pathex = ['.', './src']

reference link : https://pyinstaller.org/en/stable/spec-files.html

alternate way you can try adding src to build path Reference Link: https://pyinstaller.org/en/stable/usage.html

Sign up to request clarification or add additional context in comments.

2 Comments

I think I tried something similar.. Anyway, just tried again by doing following: 1. Added '.', './src' to main.spec pathex property. 2. Ran C:\Codes\recipy-storage> pyinstaller .\main.spec 3, Ran the exe file. However, in the end I got the same result :( ModuleNotFoundError: No module named 'src.GUI.RecipyApp'
Thank you for the update,kindly try import statement in main.py like from src.GUI import RecipyApp if it is already the same means, run in terminal: python -c "from src.GUI import RecipyApp" and for script run pyinstaller --clean --onefile --paths=./src main.py if still same issue means kindly share debug log or screenshot will help for better understanding

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.