我正在调试一些必须在我的虚拟机上运行的python脚本.而且,我更喜欢在本地编辑脚本(在虚拟机之外).所以我发现每次都要将脚本修改为虚拟机是很繁琐的scp.有人能建议一些有效的方法吗?
特别是,我想知道是否可以在远程PVM上执行python脚本.像这样的东西:
python --remote user@192.168.1.101 hello.py //**FAKED**, served to explain ONLY
Run Code Online (Sandbox Code Playgroud) 我在远程机器上有一个python脚本,我想从本地机器上执行.它需要一些参数,如果我要在那台机器上运行它,我就会运行它.
python python_parallel.py --num=10 --ssh=/home/user1/path/file.txt
Run Code Online (Sandbox Code Playgroud)
目前我的本地机器上有一个运行上述脚本的python代码:
from optparse import OptionParser
parser.add_option("-n", "--num", type="int", dest="num_spice",help="Enter the number")
parser.add_option("-s", "--ssh", dest="ssh_txt",help="Enter the path to the text file")
num_spice=options.num_spice
ssh_txt=options.ssh_txt
(options, args) = parser.parse_args()
os.system('ssh user1@10.100.10.201 python /home/user1/path/python_parallel.py --num=%s --ssh=%s' %(num_spice, ssh_txt) )
Run Code Online (Sandbox Code Playgroud)
有没有更好的方法呢?我在这个链接上尝试了解决方案,但它给了我一个错误"ImportError:没有名为ssh的模块"