Trouble saving pickle file in 09 Tabular notebook?

I’m getting an error trying to save the processed kaggle dataset to file. I’m running the Tabular model Colab notebook.


gives me the error:

AttributeError Traceback (most recent call last)
in ()
----> 2 (path/‘to.pkl’).save(to)
3 type(path)
4 type(to)

AttributeError: ‘PosixPath’ object has no attribute ‘save’

Path is defined thus: path = Path(’/content/drive/MyDrive/Courses/FASTAI/bluebook’)
which makes path an object of type pathlib.PosixPath

Potentially relevant: I had to change the original path definition from path = URLs.path(‘bluebook’) because the original dir had a mkdir error (/root/.fastai/.archive/bluebook). But in any case the output of URLs.path() is also a pathlib.PosixPath, so I’m not sure where the error is?

Thanks for any leads - would be nice to save intermediate files!


Hi shraddhapai hope you are having a wonderful day!

When I use shutil to save .pkl files across different file systems, I often have to convert the posix.path to a string eg. path_string = str(posix_path) then I use this string to save files.

Maybe this approach would work for you.

Cheers mrfabulous1 :grinning: :grinning:

Hi, Thanks for that - but it doesn’t work for me.

pathstr = str(path)
(pathstr + ‘/to.pkl’).save(to)

AttributeError: ‘str’ object has no attribute ‘save’

How does the call to save need to change?


Hi shraddhapai

Maybe the link above will help.

Cheers mrfabulous1 :smiley: :smiley:


Perfect - this works, thanks so much!

(sorry for the late response, looping back after a brief hiatus - juggling other projects, but glad to be back on track!)

1 Like