最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - Can anyone help me with a FileNotFoundError? - Stack Overflow

programmeradmin2浏览0评论

I have exhausted gemini, trying to figure out why i am receiving an error message while trying to pickle a ML model for a data project. I would appreciate any advice that someone can give me. I have the correct file path. I don't know if it is a cloud issue, but i moved the folder to my local device and it is still giving me the error message.

FileNotFoundError: [Errno 2] No such file or directory: '/Users/michael/Google_rf/hr_rf1.pickle'

this is the function i am trying to use ....

def write_pickle(path, model_object, save_as:str): with open(path + save_as + ".pickle", "wb") as to_write: pickle.dump(model_object, to_write)

and i put my file path in before the function ..

path = "/Users/michael/Google_rf/"

then i called it like this .....

write_pickle(path, rf1, 'hr_rf1')

I switched the folder over to my local drive. I made sure the jupyter notebook kernal was set for python. I checked the spelling and confirmed the file path, etc..

I have exhausted gemini, trying to figure out why i am receiving an error message while trying to pickle a ML model for a data project. I would appreciate any advice that someone can give me. I have the correct file path. I don't know if it is a cloud issue, but i moved the folder to my local device and it is still giving me the error message.

FileNotFoundError: [Errno 2] No such file or directory: '/Users/michael/Google_rf/hr_rf1.pickle'

this is the function i am trying to use ....

def write_pickle(path, model_object, save_as:str): with open(path + save_as + ".pickle", "wb") as to_write: pickle.dump(model_object, to_write)

and i put my file path in before the function ..

path = "/Users/michael/Google_rf/"

then i called it like this .....

write_pickle(path, rf1, 'hr_rf1')

I switched the folder over to my local drive. I made sure the jupyter notebook kernal was set for python. I checked the spelling and confirmed the file path, etc..

Share Improve this question edited Nov 20, 2024 at 20:24 M_Sabatino asked Nov 20, 2024 at 18:34 M_SabatinoM_Sabatino 12 bronze badges 2
  • 1 Please read and follow How do I ask a good question?. In particular, there is a section 'Help others reproduce the problem'. That will lead you to How to create a Minimal, Reproducible Example that covers formatting your code as code blocks we can use. You'd see your code is unusable if you took the advice at the bottom of the guide: "Try reproducing the problem yourself, in a fresh environment and make sure you can do so using only the information included in your question." – Wayne Commented Nov 20, 2024 at 19:28
  • As to your issue, first try writing to the current working directory. Then if that works use pwd run in cells in your notebook to see where you are in your file hierarchy and then use %cd to change the working directory and use ls to see what is in the current directory. Then using those, troubleshoot what your notebook can see and demonstrate in your post to us about the presence of /Users/michaelsabatino/Google_rf/. Also, did you try path = r"/Users/michaelsabatino/Google_rf/"? – Wayne Commented Nov 20, 2024 at 19:34
Add a comment  | 

1 Answer 1

Reset to default 0

You need to format your code to make it more readable. Make sure python is running from the directory you think it is.

In your script you can simply add

import os
print(os.getcwd())

to view the actual directory you are running in. From there you can update your path as necessary.

发布评论

评论列表(0)

  1. 暂无评论