From 6ee5dff51c8a54c7dd9f345f10f33542888034eb Mon Sep 17 00:00:00 2001 From: Lyndon White Date: Fri, 9 Feb 2018 23:03:35 +0800 Subject: [PATCH] Make python 3.4 compat module loading (fix #1733) --- spacy/compat.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/spacy/compat.py b/spacy/compat.py index e50036013..3cc214b28 100644 --- a/spacy/compat.py +++ b/spacy/compat.py @@ -43,15 +43,15 @@ fix_text = ftfy.fix_text copy_array = copy_array izip = getattr(itertools, 'izip', zip) -is_python2 = six.PY2 -is_python3 = six.PY3 is_windows = sys.platform.startswith('win') is_linux = sys.platform.startswith('linux') is_osx = sys.platform == 'darwin' +is_python2 = six.PY2 +is_python3 = six.PY3 +is_python_pre_3_5 = is_python2 or (is_python3 and sys.version_info[1]<5) if is_python2: - import imp bytes_ = str unicode_ = unicode # noqa: F821 basestring_ = basestring # noqa: F821 @@ -60,7 +60,6 @@ if is_python2: path2str = lambda path: str(path).decode('utf8') elif is_python3: - import importlib.util bytes_ = bytes unicode_ = str basestring_ = str @@ -111,9 +110,11 @@ def normalize_string_keys(old): def import_file(name, loc): loc = str(loc) - if is_python2: + if is_python_pre_3_5: + import imp return imp.load_source(name, loc) else: + import importlib.util spec = importlib.util.spec_from_file_location(name, str(loc)) module = importlib.util.module_from_spec(spec) spec.loader.exec_module(module)