[英]FileNotFoundError: [Errno 2] No such file or directory (python error)
I'm new to python and I'm trying to learn it using Google Colab I'm trying to open a CSV file, but I just can't do it.我是 python 的新手,我正在尝试使用 Google Colab 学习它我正在尝试打开 CSV 文件,但我就是做不到。
import csv
open(r'C:\Users\User\Desktop\username.csv')
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
<ipython-input-30-d948a291431c> in <module>()
1 import csv
----> 2 open(r'C:\Users\User\Desktop\username.csv')
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\User\\Desktop\\username.csv'
I've already searched for similar questions, mostly of them sugest the problem is the (r'C:\completelocalfile), but I already tried, as you can see on my code, however it's not working for me.我已经搜索过类似的问题,其中大多数都认为问题是 (r'C:\completelocalfile),但我已经尝试过,正如您在我的代码中看到的那样,但它对我不起作用。 Any sugestions?
有什么建议吗?
Does this help? 这有帮助吗? Basically, Google Colab cannot access your local machine files.
基本上,Google Colab 无法访问您的本地机器文件。
As a workaround, I would suggest to upload file on you drive, mount your drive in Colab, and then load the file from there.作为一种解决方法,我建议在您的驱动器上上传文件,在 Colab 中安装您的驱动器,然后从那里加载文件。
The snippet to mount drive is the following:挂载驱动器的片段如下:
from google.colab import drive
drive.mount('/content/drive', force_remount=True)
After that, you can upload the file manually and finally you load the file with the following command:之后,您可以手动上传文件,最后使用以下命令加载文件:
filename = r'/content/drive/MyDrive/pathtoyourfile'
import csv
open(filename)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.