Merubokkusu / Discord-S.C.U.M

A Discord API Wrapper for Userbots/Selfbots written in Python.
MIT License
581 stars 170 forks source link

Trying to pack into a EXE #459

Open sufianadnan opened 1 year ago

sufianadnan commented 1 year ago

File "discum\importmanager.py", line 10, in func KeyError: 'SuperProperties'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "1.py", line 7, in File "discum\discum.py", line 89, in init File "discum\discum.py", line 222, in getSuperProperties File "discum\importmanager.py", line 12, in func ModuleNotFoundError: No module named 'discum.start' [18524] Failed to execute script '1' due to unhandled exception!

pyinstaller --noconfirm --onefile --console --add-data "/Images;Images/" "/1.py"

note the path is correct above

reconSuave commented 1 year ago

Pyinstaller isn't looking in the right place for dependencies, some things you can try:

tell pyinstaller where discum is:

 --paths "/full_path_to/venv/lib/python3.x/site-packages/discum/"

tell pyinstaller where discum.start is:

 --paths "/full_path_to/venv/lib/python3.x/site-packages/discum/start"

tell pyinstaller to collect everything under discum package:

--collect-all "discum"

tell pyinstaller to collect discum.start as a hidden import:

--hidden-import "discum.start"

if those don't solve it, there are some more exotic options like adding a runtime-hook that imports the discum package and initializes your script, or making discum into a shared library and adding it to the compiled exe and modifying your script to call the functions from the library.

But probably one of the above options, or some combination of those options, will fix it. In all likelihood you just need to tell pyinstaller where to look for dependencies. Also make sure you're running pyinstaller from the same virtual environment where discum is installed. And also on that note, sometimes it can help to make a fresh virtual environment and install the dependencies for your script in the fresh virtual environment, and then install and run pyinstaller in the same environent after dependencies are installed.

Pyinstaller can be finicky sometimes and there are multiple ways you can accomplish the same thing which is kind of annoying and unpythonic but with some experimentation you can usually find a way that works for your situation. Also you might want to consider using the auto-py-to-exe package to initialize pyinstaller, it has some advantages like being able to see all the different options for collecting dependencies so you can try them all systematically in a more organized way, and it gives you verbose output by default. In general it just makes troubleshooting easier.

Hope this helps.