在 Google Cloud Compute Engine 上运行 python 脚本 [英] Running a python script on Google Cloud Compute Engine

查看:27
本文介绍了在 Google Cloud Compute Engine 上运行 python 脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于学校的机器学习任务,我编写了自己的 MLP 网络.数据集相当大,训练需要很长时间.我被告知可以在 Google Cloud Compute Engine 上运行我的脚本的选项.我试图设置它,但没有成功(还).

For a machine learning task at school I wrote my own MLP network. The data set is quite big, and training takes forever. I was alerted to the option of running my script on the Google Cloud Compute Engine. I tried to set this up, but did not succeed (yet).

我采取的步骤:

  1. 创建一个帐户
  2. 创建虚拟机
  3. 通过浏览器打开虚拟机

谁能帮助我将我的 Python 脚本导入并运行到 Google Cloud 中.或者有没有人有关于如何解决这个问题的明确教程?我试图自己找到这些,但到目前为止没有成功.

Can anyone help me with importing and running my python script into the Google Cloud. Or does anyone have clear a tutorial on how to solve this? I tried finding these myself, but had no success so far.

推荐答案

我终于想通了,所以我会在我自己的帖子上发布相同的答案,在这里对我有用.在我的 VM 上使用 Debian Stretch.我假设您已经将文件上传到 VM,并且您位于脚本的同一目录中.

I finally figured this out so I'll post the same answer on my own post that worked for me here. Using Debian Stretch on my VM. I'm assuming you already uploaded your file(s) to the VM and that you are in the same directory of your script.

  1. 使您的脚本成为可执行文件

  1. Make your script an executable

chmod +x myscript.py

  • 运行 nohup 命令在后台执行脚本.& 选项确保进程在退出后保持活动状态.我已将shebang行添加到我的python脚本中,因此无需在此处调用python

  • Run the nohup command to execute the script in the background. The & option ensures that the process stays alive after exiting. I've added the shebang line to my python script so there's no need to call python here

    nohup /path/to/script/myscript.py &
    

  • 如果需要,请从 shell 注销

  • Logout from the shell if you want

    logout
    

  • 完成!现在您的脚本已启动并正在运行.您可以通过检查此命令的输出重新登录并确保您的进程仍然存在:

    Done! Now your script is up and running. You can login back and make sure that your process is still alive by checking the output of this command:

    ps -e | grep myscript.py
    

    如果出现任何问题,您可以查看 nohup.out 文件以查看脚本的输出:

    If anything went wrong, you can check out the nohup.out file to see the output of your script:

    cat nohup.out
    

    这篇关于在 Google Cloud Compute Engine 上运行 python 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆