PosixPath and mkdir exist_ok bugs in notebooks


(karenerobinson) #1

I am getting two errors everywhere that I think must be related to configuration. One is that open() does not accept PosixPaths but rather wants os.PathLike or strings; the other is that mkdir() does not accept an exist_ok flag. Neither makes any sense to me.

Minimal notebook to reproduce:

from fastai.text import *

CLAS_PATH=Path('data/imdb_clas/')
CLAS_PATH.mkdir(exist_ok=True)
# generates error:
# TypeError: mkdir() got an unexpected keyword argument 'exist_ok'

CLAS_PATH.mkdir()
# no error
# ok the directory is created, let's try opening a file

open(CLAS_PATH/'file.txt')
# generates error:
# TypeError: expected str, bytes or os.PathLike object, not PosixPath

open(str(CLAS_PATH/'file.txt'),'wb')
# no error

Here is some additional info on my system:

I am using an AWS P2.large instance for the course.

fwiw I get the same behavior when running python from a prompt in my ssh shell on the AWS machine.

(fastai) ubuntu@ip-10-0-0-10:$ python --version
Python 3.6.4 :: Anaconda, Inc.

Same answer in the notebook just to be sure:

 import sys
 sys.version
 '3.6.4 |Anaconda, Inc.| (default, Jan 16 2018, 18:10:19) \n[GCC 7.2.0]'

Part 2 lesson 11 wiki
(karenerobinson) #2

ok in case this helps anyone else I think the answer was that I had two copies of pathlib:

fastai/lib/python3.6/pathlib.py

and

fastai/lib/python3.6/site-packages/pathlib.py

I think uninstalling and reinstalling pathlib should work, but I manually removed the site-packages file (which didn’t have fspath defined in it—I checked with $cat pathlib.py | grep fspath ) and replaced it with the file that seemed more up to date manually.