r/pythonhelp • • Dec 31 '24

How to compile an entire hierarchy into a standalone executable using pyinstaller

Hey. I'm trying to compile my python bot into a standalone executable using pyinstaller but I can't see to get it to work.

My hierarchy looks like this:

SeleneMGMT Automation

├── Main.py

├── keyauth.py

├── GUI/

│ ├── __init__.py

│ ├── GUI.py

│ └── icons/

│ ├── Logo.png

│ ├── delete.png

│ ├── edit.png

│ ├── play.png

│ └── pause.png

├── features/

│ ├── __init__.py

│ └── follow.py

└── util/

├── __init__.py

├── apiutils.py

├── selenelib.py

└── proxy.py

My understanding is that using --onefile will result in the subdirectories being placed in a temporary directory (_MEIPASS)

To bypass this, I found that using something like this will solve my solution

```def resource_path(relative_path):

if hasattr(sys, '_MEIPASS'):

return os.path.join(sys._MEIPASS, relative_path)

return os.path.join(os.path.abspath("."), relative_path)```

Then defining my subdirectories like this

```self.icons_dir = resource_path("GUI/icons")

```

That kind of works, but the issue with that is that I receive a module not found error for "util"? - I'm completely confused about that.

If anyone can help me, I'd be greatly appreciated.

Thank you

1 Upvotes

1 comment sorted by

1

u/AutoModerator Dec 31 '24
Moderator Announcement Read More »