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

I got error when I run this line,


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)

Any help would be much appreciated.

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


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:

Load file: