如何从Google Colab笔记本的".py"文件中运行Python脚本? [英] How to run a Python script in a '.py' file from a Google Colab notebook?

查看:886
本文介绍了如何从Google Colab笔记本的".py"文件中运行Python脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

%%javascript
IPython.OutputArea.prototype._should_scroll = function(lines) {
    return false;
}

%run rl_base.py

我运行这个错误,说找不到rl_base.py文件.我已将同一文件上传到colab的gdrive中,并且从运行我的.ipynb文件的同一文件夹中上传,其中包含上面的代码

I run this giving error saying rl_base.py file not found. I have uploaded the same to gdrive in colab and from the same folder I am running my .ipynb file, containing the above code

推荐答案

如果在驱动器的相应文件夹中有test.py文件(如下面的图片所示),则可以使用该命令来运行test.py文件如下所述,

If you have the test.py file in the corresponding folder in drive as in the below attached image, then the command which you use to run the test.py file is as mentioned below,

!python gdrive/My\ Drive/Colab\ Notebooks/object_detection_demo-master/test.py

其他信息:

如果您要运行!python test.py,则应通过以下命令更改目录,

Additional Info:

If you jusst want to run !python test.py then you should change directory, by the following command before it,

%cd gdrive/My\ Drive/Colab\ Notebooks/object_detection_demo-master/

这篇关于如何从Google Colab笔记本的".py"文件中运行Python脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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