johschEleven
johschEleven

Reputation: 1

ModuleNotFoundError: No module named 'customtkinter' using Raspberry Pi and openbox

I am using a Raspberry Pi and the lite version of the OS. My goal is to run a python script using customtkinter. As I am using the lite-version of the OS, I run the script with xorg and openbox (tutorial: https://forums.raspberrypi.com//viewtopic.php?t=152264)

Executing the file that runs my script in openbox, I get the following error:

ModuleNotFoundError: No module named 'customtkinter'

Customtkinter is installed.

The python script itself is executable, if I try running the .py file itself, I get the following error:

tkinter.TclError: no display name and no $DISPLAY environment variable

That means, the file itself doesn't have the problem of importing customtkinter as the above error is caused in line 35 and I'm importing customtkinter in line 2.

So somehow running the file in openbox causes the problem of not finding the customtkinter module. How can I fix this? PS: There is no problem importing other libraries such as Tkinter

Upvotes: 0

Views: 1161

Answers (2)

EricPlayz YT
EricPlayz YT

Reputation: 11

You may need to activate your desktop environment, using the simple startx command. If you don't have a desktop environment installed on your Pi, you can use apt, apt-get or aptitude to install any desktop environment of your choice.

Upvotes: 0

Cory Bond
Cory Bond

Reputation: 11

I was banging my head against this same issue with a python GUI in openbox I am building.

While analyzing the python path within the application I did notice one of the local package folders was not present when run through openbox. Running the below:

import sys

print(sys.path)

Almost all paths in the array were the same except a xxxxxx/.local/lib/python3.9/site-packages directory. This was present when running the python app through command line but not present when running sudo startx openbox-session. If you then add the following to the openbox environment file:

export PYTHONPATH=$PYTHONPATH:xxxxxxxx/.local/lib/python3.9/site-packages

either in $HOME/.config/openbox/environment or /etc/xdg/openbox/environment then that resolves the import issue.


The PythonPath variable might not be set to include that .local subpath because of the use of sudo but I haven't been able to verify this yet since I get a ~/usr/lib/xorg/Xorg.wrap: Only console users are allowed to run the X server for non-sudo users.

EDIT: I was able to run startx open-session after reinstalling the packages and modifying some startx configs and can confirm my suspicision. The $HOME/.local path isn't added in when running with sudo. If you were using sudo previously, not using sudo would be my recommended fix.

Your situation might be different though, especially how your running openbox or setting its environment.

Upvotes: 0

Related Questions