简体   繁体   English

FileNotFoundError: [Errno 2] 没有这样的文件或目录(python 错误)

[英]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.

相关问题 FileNotFoundError: [Errno 2] 没有这样的文件或目录 Azure Python 错误 - FileNotFoundError: [Errno 2] No such file or directory Azure Python error Python 错误:FileNotFoundError: [Errno 2] 没有那个文件或目录 - Python error: FileNotFoundError: [Errno 2] No such file or directory Python 错误 FileNotFoundError: [Errno 2] 没有这样的文件或目录: - Python error FileNotFoundError: [Errno 2] No such file or directory: Python: FileNotFoundError: [Errno 2] No such file or directory 错误 - Python: FileNotFoundError: [Errno 2] No such file or directory error Python 错误 FileNotFoundError: [Errno 2] 没有这样的文件或目录 - Python Error FileNotFoundError: [Errno 2] No such file or directory python:FileNotFoundError:[Errno 2]没有这样的文件或目录 - python: FileNotFoundError: [Errno 2] No such file or directory Python FileNotFoundError:[错误2]没有这样的文件或目录 - Python FileNotFoundError: [Errno 2] No such file or directory Python FileNotFoundError: [Errno 2] 没有这样的文件或目录: - Python FileNotFoundError: [Errno 2] No such file or directory: FileNotFoundError: [Errno 2] 没有这样的文件或目录 [Python] - FileNotFoundError: [Errno 2] No such file or directory [Python] Python 3-FileNotFoundError:[Errno 2]没有这样的文件或目录 - Python 3 - FileNotFoundError: [Errno 2] No such file or directory
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM