Search code examples
google-colaboratoryoctave

Run M-file in Google Colab but got error: no such file


I want to run M-file (Octave) in Colab. first, I upload all file in Google Drive with the following address: /content/drive/MyDrive/Colab/Corroded/hybrid/FAEICA_ANN/

Then I used the following code to run my file:

!apt install octave
from google.colab import drive
drive.mount('/content/drive')
import sys
import os
py_file_location = "/content/drive/MyDrive/Colab/Corroded/hybrid/FAEICA_ANN"
sys.path.append(os.path.abspath(py_file_location))
!octave -W  MainANN_FAEICA.m

But I got:

error: no such file, '/content/MainANN_FAEICA.m'
error: source: error sourcing file '/content/MainANN_FAEICA.m'

Although I added the path, Colab cannot recognize the file.


Solution

  • You've added the directory to Python's system search path, not to Octave's search path.

    The simplest way to run this file is to change the working directory to where the file is, then run the file:

    os.chdir(py_file_location)
    !octave -W  MainANN_FAEICA.m