Can a fabric run a local script on a remote machine?

I have myfile.pyon my local machine.

I want to do something like:

from fabric.api import env, run

env.host_string = 'whatever.com'

def run_script():
    run('python myfile.py')

but of course this returns can't open file 'myfile.py': [Errno 2] No such file or directoryHow can I run this file remotely? Do i have puton whatever.com?

+4
source share
1 answer

You can first click myfile.pyon the remote computer using fabric.operations.put, and then run the script as you tried to.

But make sure that the path to your script is either an absolute path or relative to the current directory from which the remote commands are executed, this can be found using cwdyou can also manually cdin the remote folder usingfabric.context_managers.cd

+1
source

All Articles