28. February 2024

qt.qpa.plugin: Could not load the Qt platform plugin “xcb” in “” even though it was found.

After the installation of QtCreator on Linux you might get following error messag when launching the application:

qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found.

This application failed to start because no Qt platform plugin could be initialized. 
Reinstalling the application may fix this problem.

It is likely one of libraries required by xcb is missing.

To resolve this problem find libxcb.so and run ldd to identify the missing library.

find ~/Qt -name libqxcb.so -exec ldd {} \; | grep "not found"

Install the missing dependency. E.g.:

sudo apt-get install libxcb-cursor0

2. April 2022

ESP32 Arduino macOS exec: “python”: executable file not found in $PATH

Apple removed old Python 2 from macOS 12.3. Arduino ESP32 depends on Python interpreter.

Build in Arduino IDE may fail with error:

"python": executable file not found in $PATH

It’s sufficient to change name of binary to python3

Edit file

~/Library/Arduino15/packages/esp32/hardware/esp32/2.0.2/platform.txt

Change the line:

tools.gen_esp32part.cmd=python "{runtime.platform.path}/tools/gen_esp32part.py"

To line with python3:

tools.gen_esp32part.cmd=python3 "{runtime.platform.path}/tools/gen_esp32part.py"

Re-open Arduino IDE and build the project.

3. November 2021

Pipenv on Windows fails AttributeError: ‘NoneType’ object has no attribute ‘version_sort’

There is an issue with Python Pipenv on Windows.

The command to open shell with isolated pipenv you can use command:

python -m pipenv shell

The command might fail on Windows with a strange error like this:

Traceback (most recent call last):
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2032.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2032.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\User\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pipenv\__main__.py", line 5, in <module>
    cli()
  File "C:\Users\User\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pipenv\vendor\click\core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "C:\Users\User\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pipenv\vendor\click\core.py", line 782, in main
    rv = self.invoke(ctx)
  File "C:\Users\User\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pipenv\vendor\click\core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "C:\Users\User\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pipenv\vendor\click\core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "C:\Users\User\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pipenv\vendor\click\core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "C:\Users\User\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pipenv\vendor\click\decorators.py", line 73, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "C:\Users\User\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pipenv\vendor\click\core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "C:\Users\User\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pipenv\cli\command.py", line 429, in shell
    do_shell(
  File "C:\Users\User\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pipenv\core.py", line 2356, in do_shell
    ensure_project(
  File "C:\Users\User\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pipenv\core.py", line 576, in ensure_project
    ensure_virtualenv(
  File "C:\Users\User\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pipenv\core.py", line 498, in ensure_virtualenv
    python = ensure_python(three=three, python=python)
  File "C:\Users\User\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pipenv\core.py", line 388, in ensure_python
    path_to_python = find_a_system_python(python)
  File "C:\Users\User\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pipenv\core.py", line 350, in find_a_system_python
    return next(iter(finder.find_all_python_versions()), None)
  File "C:\Users\User\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pipenv\vendor\pythonfinder\pythonfinder.py", line 328, in find_all_python_versions
    path_list = sorted(versions, key=version_sort, reverse=True)
AttributeError: 'NoneType' object has no attribute 'version_sort'

The problem is caused by pythonfinder.py which is trying to locate a Python.

You can override the pythonfinder.py by explicitly defining the version of the Python.

Determine the version of installed Python:

python --version

Specify the Python version when starting the shell:

python -m pipenv shell --python 3.9.7

The Python environment should start correctly.

20. May 2021

Xcode: How to quickly filter only errors from the build

The best software practice tells you that you should not have build warnings in the projects. It’s easier to spot a potential problem.

Sometimes it’s necessary to import larger portion of code which generates many warnings and it’s very hard to find the error which blocks compilation of iOS or macOS application in Xcode.

The quick way to filter out warnings and see only errors in Xcode is to click X icon at the bottom of Issue Navigator with the title “Show only errors”:

20. April 2021

How to statically link Rust application for Windows

Rust compiler can generate a single binary that contains all dependencies. This is a great feature for creating stand-alone tools or tools for containers.

There is one gotcha for Windows which does not appear on a developer’s machine. When you move the application to a brand new installation of Windows or you try to start the in Windows Docker Container which contains Windows for Datacenters the app won’t start.

Why? The system is missing Microsoft Visual C++ Redistributable 2015-2019 (vc_redist) which you can download from microsoft.com.

It’s quite inconvenient to force the user to install the package in the case of a stand-alone Rust tool. The package installation even requires elevation of privileges.

The alternative approach to distributing vc_redist is to statically link CRT library into the application. It will result in a slightly bigger application around +100KB.

It’s necessary to tell rustc to perform static linking of CRT.

In the project create file .cargo/config.toml:

[target.x86_64-pc-windows-msvc]
rustflags = ["-C", "target-feature=+crt-static"]

Rebuild the application and the new binary is statically linked and can run even on Windows 8 without vc_redist.

The interesting part is how to determine the proper target name which is on the first line of the example configuration. Many examples on the internet are referring to target.i686-pc-windows-msvc which does not work. Use the following command to determine parts of the name of the target:

rustc --print cfg
target_arch="x86_64"
target_endian="little"
target_env="msvc"
target_family="windows"
target_feature="fxsr"
target_feature="sse"
target_feature="sse2"
target_os="windows"
target_pointer_width="64"
target_vendor="pc"
windows

The target name is composed of values on the lines above.