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
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:
Almost all paths in the array were the same except a
xxxxxx/.local/lib/python3.9/site-packagesdirectory. This was present when running the python app through command line but not present when runningsudo startx openbox-session.If you then add the following to the openbox environment file:either in
$HOME/.config/openbox/environmentor/etc/xdg/openbox/environmentthen that resolves the import issue.The PythonPath variable might not be set to include that .local subpath because of the use ofsudobut 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 serverfor non-sudo users.EDIT: I was able to run
startx open-sessionafter reinstalling the packages and modifying some startx configs and can confirm my suspicision. The$HOME/.localpath 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.