Python Forum

Full Version: Start my program in RPI4B from SSH and Failed
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have a python program and executed (python3 myprogram1.py) from the terminal in the RPI4B works perfectly.
I wanted to run on RPI4B without the keyboard and mouse and not want use an VNC.

But when I use a terminal from windows 10 on my pc with SSH remote and tried to run my program, it said:
Output:
pi@raspberrypi:~/python $ python3 myprogram1.py Traceback (most recent call last): File "myprogram1.py", line 12, in <module> from pynput.mouse import Controller File "/home/pi/.local/lib/python3.7/site-packages/pynput/__init__.py", line 40, in <module> from . import keyboard File "/home/pi/.local/lib/python3.7/site-packages/pynput/keyboard/__init__.py", line 31, in <module> backend = backend(__name__) File "/home/pi/.local/lib/python3.7/site-packages/pynput/_util/__init__.py", line 82, in backend if resolutions else '') ImportError: this platform is not supported: ('failed to acquire X connection: Bad display name ""', DisplayNameError('')) Try one of the following resolutions: * Please make sure that you have an X server running, and that the DISPLAY environment variable is set correctly
I think I must something missing with the command line?
GUI programs that use Xwindows aren't directly executable on other machines through SSH.

If your local machine can run an X sserver, you can forward it through an SSH session. But that would be unusual for someone to run an X server on windows. It is possible though.

Why do you not want to run VNC? It's easier to run VNC client on windows than it is to run a full Xserver and then have the pi connect to it.

Or, could you have your program run in a command-line mode? Without a GUI, it's much easier to run non-web programs remotely.
I mean I just want to launch the program to the RPI4B itself.

For example:
- I open the PuTTY with SSH and connected with the RPI4B.
- I type python3 myprogram1.py
- the RPI4B to launch the myprogram1.py to run on RPI4B's LCD itself.

that's all.
I found from other forum.

use DISPLAY=:0.0 python3 myprogram1.py

it's worked!


Thank you for your helps.