如何在通过putty打开的远程机器上运行python脚本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29604188/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 04:47:15  来源:igfitidea点击:

How to run python script in remote machine opened through putty

pythonsshputty

提问by Anusha R

I have a python program which I run in the python shell. Now I open putty with a host name through ssh connection. I login with username and password. Now my problem is that my python program has to run in this remote server that I have opened through putty. The output files that this python program generates has to be stored in the remote server only. Should I copy my python script to the remote server and install python in the remote server to run my script? Or is there any other way this can be done? How to install specific python modules in the remote server?

我有一个在 python shell 中运行的 python 程序。现在我通过 ssh 连接用主机名打开 putty。我用用户名和密码登录。现在我的问题是我的python程序必须在我通过腻子打开的这个远程服务器上运行。这个 python 程序生成的输出文件只能存储在远程服务器中。我应该将我的 python 脚本复制到远程服务器并在远程服务器中安装 python 来运行我的脚本吗?或者有没有其他方法可以做到这一点?如何在远程服务器中安装特定的 python 模块?

回答by MartinsM

Yes, you have to copy your python script to the remote server.

是的,您必须将 python 脚本复制到远程服务器。

Here is a link on how to copy files to a remote server using putty.

这是有关如何使用 putty 将文件复制到远程服务器的链接。

If you are connecting through putty then your server should be (I think so) Unix/Linux. Exe files won't work there, but the Python should be installed by default.

如果您通过 putty 连接,那么您的服务器应该是(我认为是)Unix/Linux。exe 文件在那里不起作用,但默认情况下应该安装 Python。

Type in the shell (command prompt) uname -aor more /etc/issueto learn what Unix/Linux there is on the remote server.

键入 shell(命令提示符)uname -amore /etc/issue了解远程服务器上的 Unix/Linux。

Navigate to the folder where you copied python script cd /my/directory/

导航到复制 python 脚本的文件夹 cd /my/directory/

Launch the script python yourscript.py

启动脚本 python yourscript.py