diff --git a/py/_path/common.py b/py/_path/common.py index 958f98fb..2364e5fe 100644 --- a/py/_path/common.py +++ b/py/_path/common.py @@ -10,6 +10,12 @@ # Moved from local.py. iswin32 = sys.platform == "win32" or (getattr(os, '_name', False) == 'nt') +try: + # FileNotFoundError might happen in py34, and is not available with py27. + import_errors = (ImportError, FileNotFoundError) +except NameError: + import_errors = (ImportError,) + try: from os import fspath except ImportError: @@ -35,9 +41,7 @@ def fspath(path): raise try: import pathlib - except ImportError: - pass - except FileNotFoundError: # Might happen in py34. + except import_errors: pass else: if isinstance(path, pathlib.PurePath):