简体   繁体   中英

python - spaCy module won't import

I recently tried to install the spaCy module for python 3.x. The installation looks like it runs successfully (shows no errors), but when I try to import spaCy, or when I try to install spaCy models, I get the error below. I have tried installing spaCy using both pip install and conda install , and I have tried forcing a reinstall of numpy.

Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\core\__init__.py", 
line 16, in <module>
    from . import multiarray
ImportError: DLL load failed: The specified procedure could not be found.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\lib\runpy.py", line 183, in _run_module_as_main
mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "C:\ProgramData\Anaconda3\lib\runpy.py", line 142, in _get_module_details
    return _get_module_details(pkg_main_name, error)
  File "C:\ProgramData\Anaconda3\lib\runpy.py", line 109, in _get_module_details
    __import__(pkg_name)
  File "C:\ProgramData\Anaconda3\lib\site-packages\spacy\__init__.py", line 5, in <module>
    from .deprecated import resolve_model_name
  File "C:\ProgramData\Anaconda3\lib\site-packages\spacy\deprecated.py", line 8, in <module>
    from .cli import download
  File "C:\ProgramData\Anaconda3\lib\site-packages\spacy\cli\__init__.py", line 5, in <module>
    from .train import train, train_config
  File "C:\ProgramData\Anaconda3\lib\site-packages\spacy\cli\train.py", line 8, in <module>
    from ..scorer import Scorer
  File "C:\ProgramData\Anaconda3\lib\site-packages\spacy\scorer.py", line 4, in <module>
    from .gold import tags_to_entities
  File "spacy/morphology.pxd", line 25, in init spacy.gold (spacy/gold.cpp:23505)
    cdef class Morphology:
  File "spacy/vocab.pxd", line 27, in init spacy.morphology (spacy/morphology.cpp:10713)
    cdef class Vocab:
  File ".env/lib/python2.7/site-packages/Cython/Includes/numpy/__init__.pxd", line 155, in init spacy.vocab (spacy/vocab
.cpp:19463)
  File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\__init__.py", line 142, in <module>
    from . import add_newdocs
 File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\add_newdocs.py", line 13, in <module>
    from numpy.lib import add_newdoc
  File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\lib\__init__.py", line 8, in <module>
    from .type_check import *
  File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\lib\type_check.py", line 11, in <module>
    import numpy.core.numeric as _nx
  File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\core\__init__.py", line 26, in <module>
    raise ImportError(msg)
ImportError:
Importing the multiarray numpy extension module failed.  Most
likely you are trying to import a failed build of numpy.
If you're working with a numpy git repo, try `git clean -xdf` (removes all
files not under version control).  Otherwise reinstall numpy.

run spyder using spyder command from the project directory steps:

  1. Go to your cmd , run as administrator
  2. Go to your directory where you have your spyder/ files (cd C: or E: )
  3. Open your Python project then run your spyder file like I did for example

    E:\\Python data>spyder "Spyder files.py"

remove these 2 folders manually:

rm -rf /usr/local/lib/python2.7/site-packages/numpy/
rm -rf /usr/local/lib/python2.7/site-packages/numpy-1.10.4.dist-info/

Then Try to install numpy

pip install numpy

I newly had the same problem and apparently, the problem is a conflict with numpy version. Just uninstall numpy and install nupmy 1.18.4:

pip uninstall numpy

Then:

pip install numpy==1.8.14

Of course you may use conda instead of pip .. if you are using Anaconda - good luck :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM