Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
504 views
in Technique[技术] by (71.8m points)

python - 如何从Google Colab笔记本的“ .py”文件中运行Python脚本?(How to run a Python script in a '.py' file from a Google Colab notebook?)

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

%run rl_base.py

I run this giving error saying rl_base.py file not found.

(我运行此错误提示说找不到rl_base.py文件。)

I have uploaded the same to gdrive in colab and from the same folder I am running my .ipynb file, containing the above code

(我已将同一文件上传到colab中的gdrive,并且从运行我的.ipynb文件的同一文件夹中,其中包含上述代码)

  ask by user2458922 translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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,

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

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

Additional Info: (附加信息:)

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

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

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

Google云端硬盘中的文件夹结构


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...