ssh - execute a gtk python app over remote ssh? - python

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.

Related

Run a executable PyQt5 python program without a display

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.

How can we debug in VS code for python command line app (maybe launched from VS code terminal) on remote linux server connected through SSH?

I can connect to the remote linux server from VS code through SSH by using the Remote-SSH extension.
I can run linux commands from VS code terminal.
I also have the python debugger extension in VS code.
But I do not understand how do we debug python code. When we start debugging we get below options
Python file
Module
Remote Attach
Attach using process Id
For a linux command from my python repo can I connect using Process Id? Is it possible to debug this way?

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

Running remote windows GUI application through ssh

I'm using py.test to run a series of python scripts that test an external windows GUI application.
I'm trying to run these tests on a remote ssh-enabled windows machines using fabric (using Bitvise SSH server on the remote end) but of course the tests which require GUI access fail.
I know that py.test has a package called xdist, but I guess it will suffer from the same problem if the channel we use is SSH.
Has anybody solved the issue of running remote GUI applications in Windows through SSH? SSH has been quite convenient for me to run remote deployment commands, and it would logically follow that py.test would be one of such commands.

write python code in one computer and running it on another automatically

I have the following situation.
I want to write python code in my Laptop that will take more than 24 hours to run.I am using UBUNTU 12.04 lts.
Is it possible so that I write python code in my laptop, automatically send it to some remote desktop, run there and send the output result to my laptop when done?
one way suggested to me is to use openssh.
But I want to do this in the following way----
Write and Debug Python Code in my laptop.(Solved)
email the code as attachment to ****#gmail.com(Solved)
Other python program in the desktop will automatically download and run the source code(Unsolved)
and email the output file back to my gmail id.(Solved)
what is the python code to download the attachment from the latest email from a specific gmail folder?
If your remote system is windows, a good option would be to use PsExec from SysInternals.
Ex. If your script is long_running.py a typical usage would be
PsExec \\remote-server -c long_running.py
If your remote system is *nix, and your local system is Windows, you can use ssh for remote execution via Plink (part of PuTTY).
plink remote-server#user -m long_running.py
Finally if both remote and local machine are *nix systems, you can simply use ssh
ssh remote-server#user 'bash -s' < long_running.py
Note This is just some possible options, but the idea is remote execution is possible either via ssh or a similar option (like PsExec) for Windows
If both systems are running *nix, you can easily do all your dev work and debugging locally, while still executing remotely:
One time set up:
Mount a folder from the remote box locally
On your laptop, save your project/script to that (now local) folder, or set the mounted folder as your project's save path in your IDE.
Publishing:
Do work
Click the save button
Executing:
SSH into the remote box and open a new screen
Navigate to the folder you'd previously mounted, and run your script.
You can then safely detach and close ssh if necessary (ctrl+a d), and re-attach later:
3a. screen -ls (to find the screen name)
3b. screen -x screen_name
The advantage of this solution is that if you've got an ongoing project requiring frequent edits/changes, you can do all your dev work/debugging locally, and the only work required to "publish" is clicking the save button, starting the screen, and running.

Categories

Resources