Editing Locally, Running Remotely

The title says it all. I wanted to run my Python (TensorFlow) programs on my server, while editing on my laptop. Simple. The solution is not perfect, but it is useful, so I document it here. On the local machine (the laptop, where you edit your Python program) create the following script called python3.6_remote:
#!/bin/bash
ssh pinchuk@192.168.0.173 ts_wrapper -u - < $1
On the remote machine (the server, where you want the program to actually run) you create the following script called ts_wrapper:
#!/bin/bash
cd /path/in/remote/
source /path/in/remote/virtualenv/bin/activate
python3 $1
This second script has to be placed in, for example, /usr/local/bin, so it can be found. And as can be seen, it assumes that your Python stuff (e.g. TensorFlow) is installed in virtualenv there.
And that’s it. Now if you run for example python3.6_remote ./hello.py it will run the local program hello.py on the remote machine and you will get back its output.
The caviats are:
- If your local script reads a file, it will now try to read it while running in the remote machine and in
/path/in/remote. So you have to copy the data files to the remote machine. The easiest is to create on the remote machine identical folders structure. - When you use a library locally, you will have to install it also remotely to the virtualenv.
Thanks to Arcege from https://unix.stackexchange.com/questions/299657/run-local-python-script-on-remote-machine/306538 for the idea.