Skip to content
This repository has been archived by the owner on Feb 6, 2023. It is now read-only.

pyinstaller issue with qtmodern #62

Open
NetinhoDaCosta opened this issue Feb 20, 2021 · 6 comments
Open

pyinstaller issue with qtmodern #62

NetinhoDaCosta opened this issue Feb 20, 2021 · 6 comments

Comments

@NetinhoDaCosta
Copy link

NetinhoDaCosta commented Feb 20, 2021

In this post: #34 (comment)
That part with the "import importlib etc... "
Do you add that in the .spec file?
Looks like python code

I did add the bottom part/code-block in the main python code of my application.
Only attempting to figure out how to use that top part.
(adding it in either the spec file, or my main python file, still keeps the same error when opening the .exe file)
That error is:

Traceback (most recent call last):
File "my_filename.py", line 262, in (this number differs depending on my app/code)
File "qtmodern\styles.py", line 70, in dark
File "qtmodern\styles.py", line 23, in _apply_base_theme
FileNotFoundError: [Errno 2] No such file or directory: " 'C:\sers\MyName\AppData\Local\Temp_MEI166802\qtmodern\resources/styles.qss'
[36020] failed to execute script my_filename

I have been encountering this problem for quite some time now. This is a good looking style, would love to be able to use it, and get it working. I have the following questions:

I'm also not sure why it looks for that file in the Temp directory? because of MEIPASS?
Would it be possible to add these files using pyinstaller commands? like '--paths' or '--add--data' or '--resource' or '--additional-hooks-dir' for example?

Any help to get this working would be hugely appreciated.

@Jerakin
Copy link
Collaborator

Jerakin commented Feb 23, 2021

Hi, as noted in that bug report this have nothing to do with qtmodern so we are not able to fix it. What happens is that pyinstaller does not know about the files that qtmodern uses without you explicitly telling pyinstaller about them, as far as I know there is no way for us to add something in qtmodern to fix it for everyone.

That said let's see if we can help you with your issue.

That part with the "import importlib etc... "
Do you add that in the .spec file?
Looks like python code

Yes, it is python code. Which is what the .spec file is (if they haven't recently changed that).

Both of the code block should be pretty much copy and paste into the given locations. The only thing you need to make sure is that the added_file is added to your datas in your Analysis.

I'm also not sure why it looks for that file in the Temp directory? because of MEIPASS?

I am not sure but I think pyinstaller unpack your resources to be able to use them

Would it be possible to add these files using pyinstaller commands? like '--paths' or '--add--data' or '--resource' or '--additional-hooks-dir' for example?

Should be possible, this answer on stack overflow goes through how to add data with the --add-data argument. You will of course also have to find the absolute paths to the files in qtmoderns resource folder.


If you have a link to your project I can take a look if you are having problems still.

@sanzoghenzo
Copy link

Hi, as noted in that bug report this have nothing to do with qtmodern so we are not able to fix it. What happens is that pyinstaller does not know about the files that qtmodern uses without you explicitly telling pyinstaller about them, as far as I know there is no way for us to add something in qtmodern to fix it for everyone.

Actually, you can provide a hook in your package to handle this.

the hook-qtmodern.py file is as simple as that:

from PyInstaller.utils.hooks import collect_data_files

datas = collect_data_files("qtmodern", includes=["**/*.qss"])

And there's no need to check at runtime for the resources position as the previous workaround.

An alternative would be to add the hook to pyinstaller-hooks-contrib.

@NetinhoDaCosta in the meantime, you can create the hook-qtmodern.py with the code above and either use the --additional-hooks-dir CLI option or the Analysis hookdirs parameter to add the hook folder path.

@Jerakin
Copy link
Collaborator

Jerakin commented Aug 24, 2021

Awsome find @sanzoghenzo Would you mind creating a PR for qtmodern over there?

@sanzoghenzo
Copy link

Sure! I'm on it.

I opened an issue because I don't know how to handle the optional qt wrappers dependencies and make the test pass.
I'll send a PR as soon as I got an anwser.

@sanzoghenzo
Copy link

Simpler than I thought, we pick PyQt5 and run the test with it.

PR submitted!

@sanzoghenzo
Copy link

PR merged, too bad that they released a new version just yesterday...
Let's wait the next one!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants