使用 Spyder 导入 spaCy 时出现 ImportError

ImportError when importing spaCy using Spyder

我还是 Python 的新手。我在 python (v2.7) 中导入 spaCy 时遇到问题,在 ipython (v5.4.1) 中使用它时不会出现问题。我以前有 spaCy 2.0.11,然后我重新安装了 2.0.7,问题仍然存在。

关于 spaCy 模型和我拥有的 python 版本的一些有用信息:

Python version     2.7.14         
    Platform           Darwin-15.5.0-x86_64-i386-64bit
    spaCy version      2.0.7          
    Location           /Users/AMAL/anaconda2/lib/python2.7/site-packages/spacy
    Models             en_core_web_sm, en_default

薄版:

Name: thinc
Version: 6.10.2

使用 ipython 执行 import spacy 和其他导入不会导致任何问题,并且在终端中使用 python 解释器时:

python
Python 2.7.14 |Anaconda custom (64-bit)| (default, Oct  5 2017, 02:28:52) 
[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import spacy
>>> import thinc
>>> import thinc.neural
>>> from thinc.neural.util import copy_array
>>> exit()

这是我的代码:

import re
import string
import math
from itertools import chain
from spacy.en import English '''Error triggered here'''

但是,使用 Spyder IDE 首先会抛出这个错误:

  File "/Users/AMAL/anaconda2/lib/python2.7/distutils/command/build_ext.py", line 499, in build_extension
    depends=ext.depends)

  File "/Users/AMAL/anaconda2/lib/python2.7/distutils/ccompiler.py", line 574, in compile
    self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)

  File "/Users/AMAL/anaconda2/lib/python2.7/distutils/unixccompiler.py", line 124, in _compile
    raise CompileError, msg

ImportError: Building module thinc.neural.optimizers failed: ['ImportError: Building module thinc.neural.ops failed: ["CompileError: command \'gcc\' failed with exit status 1\n"]\n']  

然后在第二次编译时错误发生变化并保持不变:

Traceback (most recent call last):

  File "<ipython-input-3-3743c1a24668>", line 1, in <module>
    runfile('/Users/AMAL/p1', wdir='/Users/AMAL')

  File "/Users/AMAL/anaconda2/lib/python2.7/site-packages/spyder/utils/site/sitecustomize.py", line 705, in runfile
    execfile(filename, namespace)

  File "/Users/AMAL/anaconda2/lib/python2.7/site-packages/spyder/utils/site/sitecustomize.py", line 94, in execfile
    builtins.execfile(filename, *where)

  File "/Users/AMAL/p1", line 14, in <module>
    from spacy.en import English

  File "/Users/AMAL/anaconda2/lib/python2.7/site-packages/spacy/__init__.py", line 4, in <module>
    from .cli.info import info as cli_info

  File "/Users/AMAL/anaconda2/lib/python2.7/site-packages/spacy/cli/__init__.py", line 1, in <module>
    from .download import download

  File "/Users/AMAL/anaconda2/lib/python2.7/site-packages/spacy/cli/download.py", line 10, in <module>
    from .link import link

  File "/Users/AMAL/anaconda2/lib/python2.7/site-packages/spacy/cli/link.py", line 7, in <module>
    from ..compat import symlink_to, path2str

  File "/Users/AMAL/anaconda2/lib/python2.7/site-packages/spacy/compat.py", line 11, in <module>
    from thinc.neural.util import copy_array

  File "/Users/AMAL/anaconda2/lib/python2.7/site-packages/thinc/neural/__init__.py", line 1, in <module>
    from ._classes.model import Model

  File "/Users/AMAL/anaconda2/lib/python2.7/site-packages/thinc/neural/_classes/model.py", line 11, in <module>
    from .. import util

ImportError: cannot import name util

我该如何解决这个问题?可能是什么问题呢?我对在我的工作中加入 spaCy 非常感兴趣,因此我们将不胜感激任何帮助。

谢谢,

(这里是 Spyder 维护者) 这个问题似乎与 Spyder 中已经报告的 bug 有关,它已在我们的 3.2.8 版本(在 March/2018 发布)。