Pygame on Raspberry Pi - no driver - python

I got a problem with setting up my Pygame code on RasPi 4. I have HDMI display (7" for now, later to be replaced by 4" on final product) connected to it (boot to console), but do all development on remote desktop.
When I use pygame 1.9, i have no problems using fbcon driver, and can show stuff on display. I now installed pygame_gui, and it pushed up the pygame version to 2.1.2. Now, I cant get the screen working, the error is
pygame 2.1.2 (SDL 2.0.14, Python 3.9.2)
Hello from the pygame community. https://www.pygame.org/contribute.html
Setting SDL variables...
...done
Checking current env variables...
SDL_FBDEV = /dev/fb0
Traceback (most recent call last):
File "/home/proto/pygameui.py", line 24, in <module>
pygame.display.init()
pygame.error: fbcon not available
I tried to set driver to fbcon, directfb, svgalib, kmsdrm, but in vain.
Trying to downgrade pygame and pygame_gui to 1.9 and 5.7 worked for normal pygame graphics, but I cant get gui stuff to work with this version..
Any idea what to do?

Found a solution in meanwhile, which is a bit bulky, but works.
I only edit from remote desktop, but start the python execution from a separate ssh console. This way, kmsdrm driver works.
When the raspi will be installed into a standalone hardware device, it would anyways autostart the python script.

Related

Vs code doesn't regognize tkinter on pop os

I have a code, where i use tkinter to make a window and stuff. It's a brawler picker for brawl stars. Im using pop os-linux and vs code and i have tried so many ways, but anything doesn't work.
When i run the code, i get this:
(.venv) sh-5.1$ python -u "/home/"my_name"/Documents/Vs-code_projektit/Joku.py"
Traceback (most recent call last):
File "/home/"my_name"/Documents/Vs-code_projektit/Joku.py", line 2, in <module>
from tkinter import *
ModuleNotFoundError: No module named 'tkinter'
And in the vs code itself, it regognizes the tkinter and turns the text green, but after that nothing relating to tkinter doesn't work and i shows an error. Btw i have the full code already cause i copied from my dual boot windows and i wanted to try it here,
What should i do to make it work?
EDIT:
For everybody who has the same problem, it may be caused by the app version. I posted this on reddit cause i didn't get answer in time, and someone suggested that i download vs code with appimage, snap, or in my case pop!_os Installation.
MAIN POINT: Someone said that NEVER use FLATPACK with ides. It may work for other apps but never use it with ides. It can't handle system packages or modules.
First of all, you need to know what interpreter is currently used by vscode, which is displayed in the lower right corner of the interface.
Clicking on the displayed python version will open a Select Interpreter panel where you can select the interpreter with the tkinter package installed to run the code
Or you can install the tkinter package for the currently used interpreter.
<path-to-current-python.exe> -m pip install tkinter
EDIT
From your terminal information it can be seen that you have activated the virtual environment, but you are running the code with Code Runner.
As a reminder, Code Runner doesn't change interpreters as you select another interpreter in the Select Interpreter panel. So please use the Run Pythonn File option provided by the official Python extension to run the code.

How to doHeadless Pygame with SSH?

I am trying to create a python script with pygame to control servos with a gamepad. I want to be able to do this without a display of any kind. I am running the script on a Raspberry Pi 4 Model B with Raspbian OS and to run scripts I am using SSH from bash terminal (I've tried on VS Code terminal and git-bash terminal) on a windows computer with OS Windows 8. I've seen some work arounds for headless pygame code:
https://www.pygame.org/wiki/HeadlessNoWindowsNeeded
https://gist.github.com/illume/f2fcdde9478aa3f1db8f3ee17359cf1c
Pygame headless setup
Pygame display init on headless Raspberry Pi Zero (Raspbian Buster Lite)
Pygame on Pi running through Putty, no screen, no input
Pygame on Pi running through Putty, no screen, no input
However, none have worked and I keep getting these errors:
Traceback (most recent call last):
File "ps4ServoControl.py", line 15, in <module>
pygame.display.init()
pygame.error: Unable to open a console terminal
or
Traceback (most recent call last):
File "ps4ServoControl.py", line 63, in <module>
for event in pygame.event.get():
pygame.error: video system not initialized
I've tried every variation of the following lines:
os.environ["SDL_VIDEODRIVER"] = "dummy"
os.putenv('SDL_VIDEODRIVER', 'fbcon')
os.putenv('DISPLAY', ':0.0')
pygame.display.init()
screen = pygame.display.set_mode((1,1))
Is it just because I'm trying to do this with SSH? I'm not sure how else to test my scripts without doing a remote desktop, but again, I don't want to have to pull up a screen somewhere when I get the script working. Any help is appreciated. Thanks!
In my case, I was headless and using pygame for sounds. The code you showed used to work for me, but after updating this year I was getting the same error. I resolved it by commenting out the following lines:
pygame.display.init()
screen = pygame.display.set_mode((1,1))
Everything seems to be fine without them.

Mac homebrew Idle3.7.1 Crashes on Mojave 10.14 Beta

When I open idle through the terminal, idle opens fine but as soon as I try to scroll over the idle window or make any slightly quick movements of the idle window, it immediately crashes with error:
Traceback (most recent call last):
File "/usr/local/bin/idle3", line 5, in <module>
main()
File "/usr/local/Cellar/python/3.7.1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/idlelib/pyshell.py", line 1552, in main
root.mainloop()
File "/usr/local/Cellar/python/3.7.1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/tkinter/__init__.py", line 1283, in mainloop
self.tk.mainloop(n)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
I have tried the command brew reinstall python --with-tcl-tk with no luck. I only get the error Error: invalid option: --with-tcl-tk.
I have tried to uninstall and reinstall completely a few times with no luck. I am using Tk version 8.5.9, I have updated that with brew but it seems that python is still using the old version.
While I don't know what the cause is, I was able to find a solution.
In idlelib/editor.py
If, you comment-out line 149, IDLE stops crashing when you try to scroll.
149 text.bind('<MouseWheel>', self.mousescroll)
150 text.bind('<Button-4>', self.mousescroll)
151 text.bind('<Button-5>', self.mousescroll)
This needs to be changed to:
149 ##text.bind('<MouseWheel>', self.mousescroll) # Now IDLE should work
150 text.bind('<Button-4>', self.mousescroll)
151 text.bind('<Button-5>', self.mousescroll)
This also seems to not break anything, but does fix the issue.
You can find this file by running
>>> import idlelib.editor
>>> idlelib.editor
<module 'idlelib.editor' from '/usr/local/Cellar/python/3.7.2_2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/idlelib/editor.py'>
>>>
Tested:
macOS Mojave 10.14.3
Python 3.7.2 (From brew install python)
Tcl/Tk (8.5.9)
Update
The problem was also corrected by reinstall python from python.org.
Previously I was using a brew installation, which seems to have introduced the problem.
I just today update my Macbook Air to Mojave and Python 3.7.1, the latter with the PSF python.org installer, which installs tcl/tk 8.6.8 and tkinter compiled to work with that. IDLE tests pass and IDLE runs normally as far as I manually tested. I strongly recommend you do the same. I cannot support any other installation.
In my opinion, https://www.python.org/download/mac/tcltk/ should be updated to call 8.5.9 'Not Recommended'. See the last section "How Python Chooses Which Tk Library To Use" on how to get Python to recognize a newer 8.5.x
Apparently, there are even issues with tk 8.6.8 on Mojave. The Mac tk developer just wrote on the Python tracker today that there are changes in tk tip to accommodate Mojave API changes. 8.5 is no longer being updated.

How do I run Pygame on Pycharm

I am trying to run pygame on the PyCharm IDE, I have installed the latest version of pygame for python 3.5 and have added it to the project interpreter. I installed pygame from http://www.lfd.uci.edu/~gohlke/pythonlibs/#pygame and copied it too python35-32/Scripts/. The test program below runs fine in the python shell but I want to run it from PyCharm.
I have been trying to solve this for the past hour and I've hit a wall.
When I run this simple test program to see if pygame is working:
import pygame
pygame.init()
pygame.display.set_mode((800, 800))
I get this error:
Traceback (most recent call last):
File "C:/Users/jerem/PycharmProjects/Games/hello_pygame.py", line 1, in <module>
import pygame
File "C:\Users\jerem\AppData\Roaming\Python\Python35\site-packages\pygame\__init__.py", line 141, in <module>
from pygame.base import *
ImportError: No module named 'pygame.base'
Any help would be greatly appreiciated!
Thanks again,
JC
Follow the instructions provided here. I think its related to the problem you are having on pygame and PyCharm on windows.
How do I download Pygame for Python 3.5.1?
its bcus pycharme has not recognised you're env or working on wrong env
https://www.jetbrains.com/help/pycharm/creating-virtual-environment.html
check this

"Python.exe has stopped working" with keyring module in Windows Vista

I'm running Python 3.3.5 with Keyring 3.8 on an MS Vista SP2 machine. The issue occurs in both normal and safe mode. I've been running this same program on an XP SP3 machine without issue.
The part of the code that causes the problem is...
import keyring
keyring.set_password("Test_Service","MyUser","Password123")
Python freezes and I get this error.
Clicking "close program" restarts the python shell.
The windows event viewer has this.
Faulting application pythonw.exe, version 0.0.0.0, time stamp 0x531c3653,
faulting module ntdll.dll, version 6.0.6002.18881, time stamp 0x51da3e27,
exception code 0xc0000374, fault offset 0x000b06fc, process id 0x1104,
application start time 0x01cf7d9df6c97176.
A quick google has ntdll.dll as a windows API library.
Any ideas as to why this is happening? How to fix? Or whether there are alternate modules?
Edit: In the mean time I have ditched Keyring and decided to use a salted hash of the MachineGuid as a machine unique consistent password.

Categories