Spacy: Spacy appears to install successfully, fails to import on Windows 10. Duplicate of a previous issue which was mistakenly closed.

Created on 16 May 2017  ·  9Comments  ·  Source: explosion/spaCy

ImportError                               Traceback (most recent call last)
<ipython-input-5-8e03d749e701> in <module>()
----> 1 import spacy
      2 #import textacy
      3 import pandas as pd
      4 import re
      5 

C:\ProgramData\Anaconda3\lib\site-packages\spacy\__init__.py in <module>()
      2 from __future__ import unicode_literals
      3 
----> 4 from . import util
      5 from .deprecated import resolve_model_name
      6 from .cli import info

C:\ProgramData\Anaconda3\lib\site-packages\spacy\util.py in <module>()
      3 
      4 import ujson
----> 5 import regex as re
      6 from pathlib import Path
      7 import sys

C:\ProgramData\Anaconda3\lib\site-packages\regex.py in <module>()
    392 # Internals.
    393 
--> 394 import _regex_core
    395 import _regex
    396 from threading import RLock as _RLock

C:\ProgramData\Anaconda3\lib\site-packages\_regex_core.py in <module>()
     19 from collections import defaultdict
     20 
---> 21 import _regex
     22 
     23 __all__ = ["A", "ASCII", "B", "BESTMATCH", "D", "DEBUG", "E", "ENHANCEMATCH",

ImportError: DLL load failed: The specified procedure could not be found.

1.) I have Visual Studio and C++ build tools installed. I'm able to successfully install other packages with the same dependency.
2.) I'm on Python 3.6. I don't have any other versions installed.
3.) The recommendation that some users are claiming fixes the problem (using conda to create a virtual env for Python3) isn't working.
4.) I've had no issues installing Spacy on Windows in the past.
5.) Other users are having the same problem and are not having it solved.
6.) Original closed issue here:
https://github.com/explosion/spaCy/issues/1027

As I commented in the issue, since I'm stuck on Windows for this project, I'm happy to help. CpuKnows' answer is speculative and incorrect.

Environment:

Your Environment

Python 3.6.0 :: Anaconda custom (64-bit)
Windows 10

install windows

Most helpful comment

Saw the same error as @PeterSulcs , Solved by running Anaconda prompt as administrator .

All 9 comments

Thanks for reraising this. Interesting :(. The Appveyor tests are passing on the conda-forge build of spaCy, so I wonder what's going wrong.

What happens if you simply do import regex? Is it a problem with the regex dependency, or spaCy itself?

I have same issue. In my case import regex triggers the same error message.

In [2]: import regex
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-2-71f6ceff7a36> in <module>()
----> 1 import regex

C:\Users\peter\AppData\Local\Continuum\Anaconda3\lib\site-packages\regex.py in <module>()
    392 # Internals.
    393
--> 394 import _regex_core
    395 import _regex
    396 from threading import RLock as _RLock

C:\Users\peter\AppData\Local\Continuum\Anaconda3\lib\site-packages\_regex_core.py in <module>()
     19 from collections import defaultdict
     20
---> 21 import _regex
     22
     23 __all__ = ["A", "ASCII", "B", "BESTMATCH", "D", "DEBUG", "E", "ENHANCEMATCH",

ImportError: DLL load failed: The specified procedure could not be found.

I got spacy to work on my environment by updating the regex library through conda forge.

C:\Users\peter
λ conda install regex
Fetching package metadata ...........
Solving package specifications: ..........

Package plan for installation in environment C:\Users\peter\AppData\Local\Continuum\Anaconda3:

The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    regex-2017.04.29           |           py36_0         314 KB  conda-forge

The following packages will be UPDATED:

    regex: 2017.04.05-py36_0 conda-forge --> 2017.04.29-py36_0 conda-forge

Proceed ([y]/n)? y

Fetching packages ...
regex-2017.04. 100% |###############################| Time: 0:00:00 344.80 kB/s
Extracting packages ...
[      COMPLETE      ]|##################################################| 100%
Unlinking packages ...
[      COMPLETE      ]|##################################################| 100%
Linking packages ...
[      COMPLETE      ]|##################################################| 100%
C:\Users\peter
λ ipython
Python 3.6.0 |Anaconda 4.3.0 (64-bit)| (default, Dec 23 2016, 11:57:41) [MSC v.1900 64 bit (AMD64)]
Type "copyright", "credits" or "license" for more information.

IPython 5.1.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: import regex

In [2]: exit()

C:\Users\peter
λ ipython
Python 3.6.0 |Anaconda 4.3.0 (64-bit)| (default, Dec 23 2016, 11:57:41) [MSC v.1900 64 bit (AMD64)]
Type "copyright", "credits" or "license" for more information.

IPython 5.1.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: import spacy

In [2]:

Foiled again...

Just tried to install en language pack and ran into issues related to my change in regex lib version:

C:\Users\peter
λ python -m spacy download en

    Downloading en_core_web_sm-1.2.0/en_core_web_sm-1.2.0.tar.gz

Collecting https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-1.2.0/en_core_web_sm-1.2.0.tar.gz
  Downloading https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-1.2.0/en_core_web_sm-1.2.0.tar.gz (52.2MB)
    100% |████████████████████████████████| 52.2MB 1.3MB/s

...

ml5lib->ftfy<5.0.0,>=4.4.2->spacy<2.0.0,>=1.7.0->en-core-web-sm==1.2.0)
Installing collected packages: en-core-web-sm, pathlib, regex
  Running setup.py install for en-core-web-sm ... done
  Running setup.py install for pathlib ... done
  Found existing installation: regex 2017.4.29
    DEPRECATION: Uninstalling a distutils installed project (regex) has been deprecated and will be removed in a future version. This is due to the fact that uninstalling a distutils project will only partially uninstall the project.
    Uninstalling regex-2017.4.29:
      Successfully uninstalled regex-2017.4.29
Successfully installed en-core-web-sm-1.2.0 pathlib-1.0.1 regex-2017.4.5

    Error: Couldn't link model to 'en'

    Creating a symlink in spacy/data failed. Make sure you have the required
    permissions and try re-running the command as admin, or use a virtualenv
    to install spaCy in a user directory, instead of doing a system
    installation.

    You can still import the model as a Python package and call its load()
    method, or create the symlink manually:

    C:\Users\peter\AppData\Local\Continuum\Anaconda3\lib\site-packages\en_core_web_sm\en_core_web_sm-1.2.0
    -->
    C:\Users\peter\AppData\Local\Continuum\Anaconda3\lib\site-packages\spacy\data\en

Traceback (most recent call last):
  File "C:\Users\peter\AppData\Local\Continuum\Anaconda3\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\Users\peter\AppData\Local\Continuum\Anaconda3\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\peter\AppData\Local\Continuum\Anaconda3\lib\site-packages\spacy\__main__.py", line 133, in <module>
    plac.Interpreter.call(CLI)
  File "C:\Users\peter\AppData\Local\Continuum\Anaconda3\lib\site-packages\plac_ext.py", line 1142, in call
    print(out)
  File "C:\Users\peter\AppData\Local\Continuum\Anaconda3\lib\site-packages\plac_ext.py", line 914, in __exit__
    self.close(exctype, exc, tb)
  File "C:\Users\peter\AppData\Local\Continuum\Anaconda3\lib\site-packages\plac_ext.py", line 952, in close
    self._interpreter.throw(exctype, exc, tb)
  File "C:\Users\peter\AppData\Local\Continuum\Anaconda3\lib\site-packages\plac_ext.py", line 964, in _make_interpreter
    arglist = yield task
  File "C:\Users\peter\AppData\Local\Continuum\Anaconda3\lib\site-packages\plac_ext.py", line 1139, in call
    raise_(task.etype, task.exc, task.tb)
  File "C:\Users\peter\AppData\Local\Continuum\Anaconda3\lib\site-packages\plac_ext.py", line 53, in raise_
    raise exc.with_traceback(tb)
  File "C:\Users\peter\AppData\Local\Continuum\Anaconda3\lib\site-packages\plac_ext.py", line 380, in _wrap
    for value in genobj:
  File "C:\Users\peter\AppData\Local\Continuum\Anaconda3\lib\site-packages\plac_ext.py", line 95, in gen_exc
    raise_(etype, exc, tb)
  File "C:\Users\peter\AppData\Local\Continuum\Anaconda3\lib\site-packages\plac_ext.py", line 53, in raise_
    raise exc.with_traceback(tb)
  File "C:\Users\peter\AppData\Local\Continuum\Anaconda3\lib\site-packages\plac_ext.py", line 966, in _make_interpreter
    cmd, result = self.parser.consume(arglist)
  File "C:\Users\peter\AppData\Local\Continuum\Anaconda3\lib\site-packages\plac_core.py", line 207, in consume
    return cmd, self.func(*(args + varargs + extraopts), **kwargs)
  File "C:\Users\peter\AppData\Local\Continuum\Anaconda3\lib\site-packages\spacy\__main__.py", line 33, in download
    cli_download(model, direct)
  File "C:\Users\peter\AppData\Local\Continuum\Anaconda3\lib\site-packages\spacy\cli\download.py", line 24, in download
    link_package(model_name, model, force=True)
  File "C:\Users\peter\AppData\Local\Continuum\Anaconda3\lib\site-packages\spacy\cli\link.py", line 27, in link_package
    symlink(model_path, link_name, force)
  File "C:\Users\peter\AppData\Local\Continuum\Anaconda3\lib\site-packages\spacy\cli\link.py", line 47, in symlink
    symlink_to(link_path, model_path)
  File "C:\Users\peter\AppData\Local\Continuum\Anaconda3\lib\site-packages\spacy\compat.py", line 49, in symlink_to
    orig.symlink_to(dest)
  File "C:\Users\peter\AppData\Local\Continuum\Anaconda3\lib\pathlib.py", line 1308, in symlink_to
    self._accessor.symlink(target, self, target_is_directory)
  File "C:\Users\peter\AppData\Local\Continuum\Anaconda3\lib\pathlib.py", line 394, in wrapped
    return strfunc(str(pathobjA), str(pathobjB), *args)
OSError: symbolic link privilege not held

I am having the exact same issue.
When I do try to update/install regex on Conda. I get a prompt asking to downgrade the spaCy. (see the last section of included output)

If I do follow through, I was able to import regex and spacy. However, I was not able to run the examples in the tutorial. For example:

import spacy
nlp = spacy.load('en')
texts = [u'One document.', u'...', u'Lots of documents']
iter_texts = (texts[i % 3] for i in range(100000000))
for i, doc in enumerate(nlp.pipe(iter_texts, batch_size=50, n_threads=4)):
assert doc.is_parsed
if i == 100:

break

The above code generates the following error:
Traceback (most recent call last):
File "C:\Users\Bo\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 2881, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "", line 5, in
assert doc.is_parsed

AssertionError

This is the code I used to upgrade regex and 'fix' importing spacy
C:\Users\Bo>conda install regex
Fetching package metadata .............
Solving package specifications: ..........

Package plan for installation in environment C:\Users\Bo\Anaconda3:

The following packages will be UPDATED:

regex: 2017.04.05-py36_0      conda-forge --> 2017.04.29-py36_0      conda-forge

The following packages will be DOWNGRADED due to dependency conflicts:

spacy: 1.8.2-np112py36_vc14_0 conda-forge [vc14] --> 1.7.3-np112py36_vc14_0 conda-forge [vc14]

Proceed ([y]/n)?

Thanks for the reports!

@PeterSulcs The last error might be related to this – looks like everything worked and installed, but the symlink for the model couldn't be created. So this might be solved by re-running the link or download command as admin!

@bwang12 Ah, this is interesting – I think this might actually hold the key to what's going on here.

Here's our theory: The regex library doesn't semver properly, so we have to pin it to an exact version (regex==2017.4.5 etc.). This possibly caused a dependency conflict in conda-forge, and unlike pip, conda actually checks that your versions are all consistent and compatible. It's still a little mysterious that the conda build tests all passed, though... We'll look into the feedstock and dependencies again and fix this in the next release!

Saw the same error as @PeterSulcs , Solved by running Anaconda prompt as administrator .

We're currently waiting to get spaCy v2.0 built for conda, which should hopefully fix this (it's just taking a bit longer because of Travis errors and the OSX backlogs 😓). If there are still problems with conda install and the new version, feel free to reopen.

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings