I’m learning PyInstaller for deploying Python applications, more specifically, applications developed with PyQt5. As far as I understand, it’s possible to bundle application data (or “resources”) in two ways: with PyInstaller or by using the Qt Resource System. With PyInstaller, one specifies the files to the parameter datas in the .spec file, whereas with Qt, one specifies them in the .qrc file.

The difference between them is that with PyInstaller, data is copied to be used with the application, since, technically, data is outside the binary. Thus, Qt has to request the OS to open a file:

# With PyInstaller
QtGui.QIcon('smiley.png') # 'smiley.png' is in filesystem (HDD lookup)

Whereas Qt resources are in the application:

# With Qt Resource System
QtGui.QIcon(':/smiley.png') # 'smiley.png' is in memory (RAM lookup)

In that sense, a missing “smiley.png” might be considered a programming error, since the developer has to manually enter it in the .qrc file and generate a source file with pyrcc5 or rcc.

I personally like using the Qt Resource System for icons and images, but something tells me that maybe Qt translation files (.qm) generated by Qt Linguist should be bundled separately with an application. I think the reason for this is that files in .qrc seem to me to have a sense of “requirement” to them, that is, the application knows that they are available because they are bundled into the binary. However, .qm files are not strictly necessary to an application. You can have translations, but the application may do just fine by defaulting to English if no translation is found for the user’s locale. Translations may be added over time as people from different countries start using the application.

This is my first time developing an internationalized (i18n) application, as well as using PyInstaller, so I wonder what’s the correct practice here, or if not “the correct” one, I would like to know which one you use and why.

Trả lời

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *