REgarding pyinstaller and tkinter app packaging

43 views
Skip to first unread message

Riza Dindir

unread,
Apr 3, 2024, 1:59:49 AMApr 3
to PyInstaller
Hello,

I am using python 3.12.2 and pyinstaller 6.5.0 on linux kernel 6.6.23.

Before switching to python 3.12, was using version 3.9 and was bundling a tkinter app with pyinstaller (do not remember the version of that pyinstaller though). The app was building coorectly and when run, it ran without any problems. But I was not using virtual environments.

Currently I am transitioning the app to use virtual environments to compile. Have created a venv in the project directory (.venv folder). I also set the include-system-site-packages pproperty in the pyenv.cfg file to true (I did forget to use the --system-site-packages when creating the virtual environment). That should not be a problem I believe. And I am activating this environment (with source /path/to/venv/bin/activate) before doing any builds.

I build the app as usual, when I run the app, I get the "ModuleNotFoundError: No module named 'Xlib'" error.

I have installed python3-tkinter and python3-xlib packages using the systems package manager. These went to the global site-packages.

To test the tkinter and xlib packages are installed correctly, I ran tkinter and xlib based applications, and they ran without errors (though they are single file apps for testing purposes and do not use virtual environments and are not processed with pyinstaller).

In the virtual environment I have installed the pyinstaller and using that pyinstaller am creating the executable. The reason for this was the pyinstaller version in the OS system packages had version 4.1. I wanted to use the latest pyinstaller, in case that was causing the trouble.

I have added the Xlib as the hidden module (--hidden-module), and also have added the site-packages path of the virtual env and the global site-packages to the paths (with the --paths parameter).

Any ideas on how to resolve the Xlib error.

Regards

bwoodsend

unread,
Apr 3, 2024, 4:02:24 AMApr 3
to PyInstaller
Can we get the runtime error message? And what distribution+version is this?

Riza Dindir

unread,
Apr 3, 2024, 4:30:18 AMApr 3
to PyInstaller
Note: I am sending this using the google groups page. GMail did not send my message to the group for some reason, and this might be a duplicate.

I am on void linux. No version for this. But kernel is 6.6.23_1.

The version of the packages in venv (virtual environment) are

Package                   Version
------------------------- -------
altgraph                  0.17.4
packaging                 24.0
pip                       24.0
pyinstaller               6.5.0
pyinstaller-hooks-contrib 2024.3
python-xlib               0.33 (this is from the global site-packages - not in the venv)
setuptools                69.2.0
six                       1.16.0 (this is from the global site-packages - not in the venv)

Some packages are from the global site-packages since I have include-system-site-packages=true.

Here is the error

[28380] Failed to execute script 'main' due to unhandled exception!
Traceback (most recent call last):
  File "main.py", line 5, in <module>

ModuleNotFoundError: No module named 'Xlib'

line 5 in main.py is

import tkinter;

This I think is importing the Xlib implicitly.

Please tell me if you need other information.

Regards

bwoodsend

unread,
Apr 3, 2024, 6:30:42 PMApr 3
to PyInstaller

Is just import tkinter on its own enough to trigger the issue? I’ve tried it in a Void Linux (and I blindly assumed glibc rather than musl based?) docker container and I’m seeing no signs of trouble.

> docker run --network=host -v(pwd):/io -it ghcr.io/void-linux/void-linux:latest-mini-x86_64 # xbps-install -Syu xbps bash # bash bash-5.2# cd /io/ bash-5.2# xbps-install -y python3-xlib python3-six python3-tkinter binutils bash-5.2# python -m venv --system-site-packages env bash-5.2# . ./env/bin/activate (env) bash-5.2# python -m pip install -U pip wheel setuptools (env) bash-5.2# pip install pyinstaller (env) bash-5.2# pip freeze altgraph==0.17.4 packaging==24.0 pyinstaller==6.5.0 pyinstaller-hooks-contrib==2024.3 python-xlib==0.33 setuptools==69.2.0 six==1.16.0 wheel==0.43.0 (env) bash-5.2# echo 'import tkinter; print("I have not crashed!")' > test.py (env) bash-5.2# pyinstaller test.py (env) bash-5.2# ./dist/test/test I have not crashed!

Riza Dindir

unread,
Apr 4, 2024, 12:47:54 AMApr 4
to PyInstaller
Hello

I am using glibc.

It turned out that another application was using Xlib, did not build that with pyinstaller (in the new virtual environment setting) at that time. The problem is resolved.

I also did not have the wheel package in my pip packages. Is that required? It looks like a packaging format.

Thank you for you help.

bwoodsend

unread,
Apr 4, 2024, 6:29:16 AMApr 4
to PyInstaller

I also did not have the wheel package in my pip packages. Is that required? It looks like a packaging format.

It prevents pip from installing .sdist packages in the broken legacy mode (a.k.a. eggs/zipped eggs). Pip has since changed that behaviour so its need should become less prominent with time as people stop using versions of pip that predate that change. In this case, all packages were already in .whl format so removing wheel wouldn’t have done any harm.

Riza Dindir

unread,
Apr 4, 2024, 8:16:56 AMApr 4
to PyInstaller
Thank you.
Reply all
Reply to author
Forward
0 new messages