cancel
Showing results for 
Search instead for 
Did you mean: 
Get Started Discussions
Start your journey with Databricks by joining discussions on getting started guides, tutorials, and introductory topics. Connect with beginners and experts alike to kickstart your Databricks experience.
cancel
Showing results for 
Search instead for 
Did you mean: 

File Not Found Error while reading pickle file

divyasri1504
New Contributor

Hello, there

I have a pickle file uploaded in a mounted location in databricks ( /dbfs/mnt/blob/test.pkl). I am trying to read this pickle file using the below python snippet

with open(path + "test.pkl", "rb") as f:
       bands = pickle.load(f)

But it throws FileNotFoundError: [Errno 2] No such file or directory: ' /dbfs/mnt/blob/test.pkl'. But the file is present in that location. I have tried listing using dbutils.fs.ls as well and file is present. Can anyone help me with this issue.

Thanks

1 REPLY 1

Kaniz_Fatma
Community Manager
Community Manager

Hi @divyasri1504 ,

  • Make sure you’re using the correct path to access the file. In Databricks, you should typically prefix everything with /dbfs (or dbfs:/ for native functions). Try using the full path like this:
with open("/dbfs/mnt/blob/test.pkl", "rb") as f:
    bands = pickle.load(f)
  • If you’re using the community edition, in Databricks Runtime (DBR) 7+, certain mounts are disabled. Try running your code on a DBR version less than 7.
  • Ensure that the file has the correct permissions. You can use dbutils.fs.ls("/dbfs/mnt/blob/") to verify that the file is listed.
  • Also, check if there are any restrictions on reading files from mounted locations.
  •  

    If the issue persists, consider using dbutils.fs.cp to copy the file from DBFS to a local directory (e.g., /tmp) and then read it from there:
    dbutils.fs.cp("/dbfs/mnt/blob/test.pkl", "file:///tmp/test.pkl")
    with open("/tmp/test.pkl", "rb") as f:
        bands = pickle.load(f)
    

Hopefully, one of these approaches will help you resolve the issue! 😊

If you need further assistance, feel free to ask! 

 

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.

If there isn’t a group near you, start one and help create a community that brings people together.

Request a New Group