Run a executable PyQt5 python program without a display - python

I need to run a executable PyQT5 python program without connect to any display on my Raspberry Pi on startup.
I found this post below:
Running a PyQt4 script without a display
I tried to run it with putty and not connecting to any display, it works.
But if I add the instruction into autostart file in lxsession folder and boot up the Pi without any display, it unable to autostart.
Note: I had tested to execute compiled python file in autostart, but the application cant start without a display connect to. I tried using putty to execute in terminal and it shows
pyqt could not connect to any x display
my command to run the application is as following:
xvfb-run python3 /home/pi/System_scanning/program_Execute.py
for compiled executable command is as following:
xvfb-run /home/pi/System_scanning/program_Execute
Now, that i need to run the executable file when startup without connect to any display.
I had added the command to
/home/pi/.config/lxsession/LXDE-pi/autostart
for auto start when booting, but it only works when my Raspberry Pi connected to monitor during boot up. If i remove the monitor and boot up, the application is not running, unless i log in with putty and execute the command manually.

Related

Autorun a screen session python script with arguments at boot on Raspberry Pie

I first want to say I'm not too familiar with the linux system as a whole and am learning.
Anyway, I'm trying to figure out how to autorun a terminal command on boot without having to manually login via ssh and do it myself.
After logging in as Pi, the command I run is : screen -d -m pagekite.py 80 {my-website}
What is a nice and simple way to make this autorun on startup?
Thanks!

How to hide terminal window whilst running a python script?

I'm running this code to open Google Chrome and to send me notifications for any updates on a certain website. I've been using this open source code from: https://github.com/iholdroyd/oddsmonkey_eachway_calculator_automation/blob/master/script.py
I'm running a MacOS Mojave v 10.14.3.
I want the code to run on startup/login, which I think that I can do from System Preferences>Users and Groups>Login Items.
I want the process to operate in the background and just alert me when there are any updates on the website i.e. I don't want any open windows or additional icons on my taskbar.
I added the following line of code to make the the chrome window invisible and to operate in the background:
options.add_argument("headless")
This seems to work as I am still getting notifications but there is no open chrome window. However, when I run the script there is still an open python launcher window and two terminal windows. To run the script (saved as a .py file), I have set it to Always Open with Python Launcher - I'm not sure if there's a better way to do it which reduces the number of windows which then open e.g. directly through terminal.
When I try to close the terminal window I (understandably) get the following error message:
Do you want to terminate running processes in this window?
Closing this window will terminate the running processes: Google Chrome, Google Chrome Helper (2), Google Chrome Helper (Renderer), chromedriver, Python, Google Chrome Helper (GPU).
I don't want to terminate the running processes, I just want them to operate in the background. Is there anyway that I can run the code without a terminal window having to be open on the desktop or minimised in the task bar? I've tried using automator but I'm not quite sure what to do.
I've never done any coding before so if you could let me know how to do this it would be great.
Thanks!
you can use a systemd unit file for this.
unit file format
[Unit]
Description=your_description
Wants=network-online.target
After=network-online.target
[Service]
User=root
Group=root
Type=simple
ExecStart=/usr/bin/python2.7 scipt.py
#your command you use to run script
[Install]
WantedBy=multi-user.target
name this file as : your_file.service
place this file in folder : /etc/systemd/system
Run this command to take effects : systemctl daemon-reload
Run this command to start your script : systemctl start your_file.service
Run this command to Run your script at startup : systemctl enable your_file.service
Run this command to check status of your script : systemctl start your_file.service*
Run this command to stop your script : systemctl stop your_file.service
Run this command to remove your script from startup : systemctl disable your_file.service

Linux - Open chromium from a script that runs on startup

I have a bash script that I've defined to run in startup, which runs a python script that waits for a command from another process, and when it gets it, it should open a chromium window with a certain URL.
When I run this script manually it works fine, but when the script runs from startup, I get an error (displayed in syslog):
Gtk: Can't open display
I guess that's because it's running in a startup mode so it doesn't actually have a display to "lean" on...
I was wondering if there's any way to get this work, anyway?
Thanks in advance
In your script that runs on startup try DISPLAY=:0 <command> &
To clarify DISPLAY=:0 simply sets which monitor your window opens on with 0 representing the first monitor of the local machine.

Executing python script without being connected to server

I need to execute python script on remote server (access through puTTY), but I don't have a stable Internet connection, and every time I execute the script I get problems after several minutes due to my Internet getting disconnected.
How do I remotely execute the script without being connected to server?
(e.g. I connect to server, run script, and can logout while executing)
You can use a Linux Screen, it opens a background terminal and keeps a shell active even through network disruptions.
Open the screen typing in your terminal $ screen and execute there your script, even if you lose connection it won't kill the process.
Here you will find a well explained How to for this program. I use it for my regular day working on remote.
try this
nohup your_script >/dev/null 2>&1 &
program will be running in background

ssh - execute a gtk python app over remote ssh?

I'm writing a gtk python app that I'm testing on an ubuntu laptop, however I'm writing the script on my win7 desktop (sftp to update the script the laptop).
If I try to execute the script via SSH such as:
python /path/to/app.py
It gives me errors since obviously gtk won't render a window in putty such as:
/usr/lib/python2.7/dist-packages/gtk-2.0/gtk/__init__.py:57: GtkWarning: could not open display
My question is, is there a way to execute the script via remote ssh that will open fine on the laptop? Its kind of a pain to have to save the script, then lean over and execute the script on the laptop.
Does anyone have any ideas how to do this?
Install a X server on your Windows 7: http://sourceforge.net/projects/xming/
Then, don't forget to do ssh -X when you start the remote script.

Categories

Resources