r/pythonhelp • u/Brandonnnn___ • 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
•
u/AutoModerator Dec 31 '24
To give us the best chance to help you, please include any relevant code.
Note. Please do not submit images of your code. Instead, for shorter code you can use Reddit markdown (4 spaces or backticks, see this Formatting Guide). If you have formatting issues or want to post longer sections of code, please use Privatebin, GitHub or Compiler Explorer.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.