PyQt5 bug report: Application fails to start when cwd contains non-ASCII characters

Florian Bruhin me at the-compiler.org
Fri Aug 11 12:47:00 BST 2023


Hey,

> On 8/10/23 11:15, Jean Abou Samra wrote:
> 
> [...]
> 
> It also occurs on macOS when Qt is installed in the directory in 
> question. The current working directory doesn't matter. The plugin path 
> and library path appear to be corrupted.
> 
> test.py:
> import os
> import PyQt5.QtCore as C
> print(f"\nCWD: {os.getcwd()}")
> print(f"plugin path: 
> {C.QLibraryInfo.location(C.QLibraryInfo.LibraryLocation.PluginsPath)}")
> print(f"library paths: {C.QCoreApplication.libraryPaths()}")
> 
> $ ./test.py
> CWD: /private/tmp
> plugin path: 
> /private/tmp/non-äscii/venv/lib/python3.8/site-packages/PyQt5/Qt5/plugins
> library paths: []

It looks like PySide had a very similar issue:

https://bugreports.qt.io/browse/PYSIDE-972
https://codereview.qt-project.org/c/pyside/pyside-setup/+/313946

From what I can gather, both PyQt and PySide generate an embedded
qt.conf to tell Qt where to find its stuff. It looks like PyQt5 uses
UTF-8 to write those files.

However, apparently QSettings on Qt 5 only accepts ASCII + Latin-1,
recommending to use "standard INI escape sequences" for anything outside
of ASCII:

https://doc.qt.io/qt-5/qsettings.html#Format-enum

    Following the philosophy that we should be liberal in what we accept
    and conservative in what we generate, QSettings will accept Latin-1
    encoded INI files, but generate pure ASCII files, where non-ASCII
    values are encoded using standard INI escape sequences.

So at minimum, I suppose qpycore_qt_conf() in
qpy/QtCore/qpycore_qt_conf.cpp should use .toLatin1() instead of
.toLocal8Bit() (= UTF-8 with a UTF-8 locale):

    static QByteArray qt_conf = qt_dir_name.toLocal8Bit(); 

Which would fix this for characters in latin1 at least (though I haven't
actually tested it). Ideally it'd probably use "standard INI escape
sequences" (whatever that is... standard and INI in the same sentence is
somewhat spooky), or perhaps even use QSettings to generate an INI
(not sure if that's possible, I know nothing about QSettings really).

Florian
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20230811/c37e93e5/attachment.sig>


More information about the PyQt mailing list