With colab, fastai path doesn't work at chapter 9

I got error when I run this line,

(path/‘to.pkl’).save(to)

AttributeError Traceback (most recent call last)

in () ----> 1 (path/‘to.pkl’).save(to)

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

I already used ’ !pip install fastai --upgrade’

any suggestions?

I think you need to restart your timeline after doing this, worked for me

1 Like

Got the same problem – done pip install fastai -U, restarted runtime with ctrl-M ., save is not available for Path, dir(Path) shows that 'ls', save_array’ etcare there,save` is not there.

# dir(Path)
['__bytes__',
 '__class__',
 '__delattr__',
...
 'load_array',
 'ls',
...
 'samefile',
 'save_array',
 'stat',
 'stem',
...
'write_text']

Any help would be much appreciated.

There was a breaking change, you can see in the fastcore changelog:

1.1.0

Breaking Changes

  • Remove Path.{read,write} (use Path.{read_text,write_text} instead) and change Path.{load,save} to functions load_pickle and save_pickle (#121)

Thanks a lot.

Well, save_pickle didnt work either. pickle.dump(to, open(path/'to.pkl', 'wb')) seems to do the trick.

Not sure why Path.save doesnt work, maybe I didn’t do some necessary from x import *, quite some to import, plus it’s not too clear which is for which.

With the current version (17/10/2020 - v1.2.0) it should be:

Save file:
save_pickle(path/'to.pkl',to)

Load file:
load_pickle(path/'to.pkl')

2 Likes