使用Spyder导入spaCy时的ImportError

时间:2018-05-27 14:32:56

标签: python python-2.7 spyder importerror spacy

我还是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

Thinc版本:

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纳入我的工作中,所以任何帮助都会得到真正的赞赏。

谢谢,

1 个答案:

答案 0 :(得分:0)

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