Reputation: 57
I am using the following command to run a python file. But I am getting the errors of file not found. Although I can see the files in Colab Notebooks and in Colab Notebook there is also one folder named InputData. How to fix this error? However when I use the following command t run heelo.py file it works fine.
`!python3 '/content/drive/My Drive/Colab Notebooks/3Band Graphics_modify.py'`
#ERROR
`
Traceback (most recent call last):
File "/content/drive/My Drive/Colab Notebooks/3Band_Graphics_modify.py", line 125, in <module>
main()
File "/content/drive/My Drive/Colab Notebooks/3Band_Graphics_modify.py", line 20, in main
nsample = np.save("InputData/nsample.npy",nsample)
File "<__array_function__ internals>", line 6, in save
File "/usr/local/lib/python3.6/dist-packages/numpy/lib/npyio.py", line 541, in save
fid = open(file, "wb")
FileNotFoundError: [Errno 2] No such file or directory: 'InputData/nsample.npy'`
Upvotes: 1
Views: 4479
Reputation: 12992
As discussed in the comments, the problem was within the working directory. After mounting GoogleDrive, the default working directory is /content/drive
which doesn't contain any of the user's files.
And to fix that, all you need to do is changing the working directory using the following command:
import os
os.chdir("/content/drive/My Drive/Colab Notebooks")
This will change the current working directory from /content/drive
to /content/drive/My Drive/Colab Notebooks
where the Original Poster has all the needed files.
Then, to run a python script in Jupyter Notebooks, you can use the magic command %run
.
Upvotes: 2
Reputation: 121
Try this:
!python3 './content/drive/My Drive/Colab Notebooks/3Band Graphics_modify.py'
Upvotes: 0