AI enthousiast
AI enthousiast

Reputation: 19

Getting 'ValueError: File path is not a valid file or URL' when using PyPDFLoader with a valid file path

import os 
import openai
import sys
sys.path.append('../..')
from dotenv import load_dotenv, find_dotenv
_=load_dotenv(find_dotenv())
openai.api_key ="my_key"
from langchain.document_loaders import PyPDFLoader
loader = PyPDFLoader("C:\\Users\\LENOVO\\Documents\\MachineLearning-Lecture01.pdf")

In my code, I've made sure to use the 'r' prefix to treat backslashes as literal characters in the file path, used double backslashes to escape them properly, and double-checked that the file indeed exists at the specified location "C:\Users\LENOVO\Desktop\MachineLearning-Lecture01.pdf." However, despite these precautions, I'm consistently receiving a 'ValueError' stating that the file path is not recognized as a valid file or URL when using the PyPDFLoader.

How to resolve this issue and successfully load the PDF file?

Upvotes: 0

Views: 4906

Answers (2)

AI enthousiast
AI enthousiast

Reputation: 19

To address the issue, I uploaded the file directly to Google Colab and then utilized the following line of code to read it:

loader = PyPDFLoader("MachineLearning-Lecture01.pdf")

This allowed me to access and work with the file in Colab seamlessly.

Upvotes: -1

DrJay
DrJay

Reputation: 469

Could it be that you misstyped in your answer, or have you actually checked the wrong path? in your code you have:

loader = PyPDFLoader("C:\Users\LENOVO\Documents\MachineLearning-Lecture01.pdf")

and in your text you have:

"C:\Users\LENOVO\Desktop\MachineLearning-Lecture01.pdf."

so, one is in "Documents" and the other in "Desktop"

Upvotes: -1

Related Questions