简体   繁体   English

为什么在 jupyter 笔记本上读取 pdf 文件时出现文件未找到错误?

[英]Why am I getting a file not found error when reading a pdf file on jupyter notebook?

I'm trying to open a file in Jupyter notebook (first time using after only using atom).我正在尝试在 Jupyter 笔记本中打开一个文件(第一次使用后仅使用 atom)。 I'm getting an error that it can't read the file path.我收到一个错误,它无法读取文件路径。 I'm sure the file path is correct, though.不过,我确定文件路径是正确的。 Your help is appreciated.感谢您的帮助。 I tried the regular open method and open with os.我尝试了常规的打开方法并使用 os.open 方法打开。

import PyPDF2
import os
path = "M:\2020\BD NY\Month End\01 - Jan 2020\Pershing - LBG\01.31.2020 - LBG - AVERAGE PRICE.pdf"
os.startfile(path)
pdfFileObj = open(path)

And my error:我的错误:


FileNotFoundError Traceback (most recent call last) in 2 import os 3 path = "M:\2020\BD NY\Month End\01 - Jan 2020\Pershing - LBG\01.31.2020 - LBG - AVERAGE PRICE.pdf" ----> 4 os.startfile(path) 5 pdfFileObj = open(path) FileNotFoundError Traceback(最近一次调用最后一次)在 2 import os 3 path = "M:\2020\BD NY\Month End\01 - Jan 2020\Pershing - LBG\01.31.2020 - LBG - AVERAGE PRICE.pdf" --- -> 4 os.startfile(路径) 5 pdfFileObj = 打开(路径)

FileNotFoundError: [WinError 2] The system cannot find the file specified: 'M:\x820\BD NY\Month End\x01 - Jan 2020\Pershing - LBG\x01.31.2020 - LBG - AVERAGE PRICE.pdf' FileNotFoundError: [WinError 2] 系统找不到指定的文件:'M:\x820\BD NY\Month End\x01 - Jan 2020\Pershing - LBG\x01.31.2020 - LBG - AVERAGE PRICE.pdf'

Are you running this on Windows or Linux?您是在 Windows 或 Linux 上运行它吗? If you're on Windows,then you should be use a path like (using \\ )如果您使用的是 Windows,那么您应该使用类似的路径(使用\\

C:\\Users\\apple\\Downloads\train.csv

A simple way is to move your files to be read under the same folder of your python file, then you just need to use the name of the file, without calling another path.一个简单的方法是将要读取的文件移动到 python 文件的同一文件夹下,然后您只需要使用文件名,而无需调用其他路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM