Skip to content

Provide compat that works with on Windows with Py 3.7.1 #2948

@cicorias

Description

@cicorias

Feature description

The script that creates the symbolic link doesn't work by default when running python -m spacy link en_core_web_sm en -- normally if Dos is the default shell a call to mklink just works. However, in via this module, it does not and it is not a permission issues nor a system policy restriction as just running mklink /d ... from the same shell/command line works..

This fails regardless if under a virtualenv as well.

Instead a user is presented with the following error message.

(venv) C:\g\py\spacy> python -m spacy link en_core_web_sm en
C:\Program Files\Python37\lib\importlib\_bootstrap.py:219: RuntimeWarning: cymem.cymem.Pool size changed, may indicate binary incompatibility. Expected 48 from C header, got 64 from PyObject
  return f(*args, **kwds)
C:\Program Files\Python37\lib\importlib\_bootstrap.py:219: RuntimeWarning: cymem.cymem.Address size changed, may indicate binary incompatibility. Expected 24 from C header, got 40 from PyObject
  return f(*args, **kwds)

    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. You can still import the model as a module and call its
    load() method, or create the symlink manually.

    C:\g\py\spacy\venv\lib\site-packages\en_core_web_sm -->
    C:\g\py\spacy\venv\lib\site-packages\spacy\data\en

Traceback (most recent call last):
  File "C:\Program Files\Python37\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\Program Files\Python37\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\g\py\spacy\venv\lib\site-packages\spacy\__main__.py", line 31, in <module>
    plac.call(commands[command], sys.argv[1:])
  File "C:\g\py\spacy\venv\lib\site-packages\plac_core.py", line 328, in call
    cmd, result = parser.consume(arglist)
  File "C:\g\py\spacy\venv\lib\site-packages\plac_core.py", line 207, in consume
    return cmd, self.func(*(args + varargs + extraopts), **kwargs)
  File "C:\g\py\spacy\venv\lib\site-packages\spacy\cli\link.py", line 48, in link
    symlink_to(link_path, model_path)
  File "C:\g\py\spacy\venv\lib\site-packages\spacy\compat.py", line 87, in symlink_to
    orig.symlink_to(dest)
  File "C:\Program Files\Python37\lib\pathlib.py", line 1320, in symlink_to
    self._accessor.symlink(target, self, target_is_directory)
OSError: symbolic link privilege not held

The following command works regardless and has no issue with permissions nor policy. The error message indicating symbolic link privilege not held is misleading.

cmd /c mklink /k c:\path\to\symlink c:\target\file

A suggestion is changing the respective lines in venv\Lib\site-packages\spacy\compat.py (symlink_to)

def symlink_to(orig, dest):
    if is_python2 and is_windows:
        import subprocess
        subprocess.call(['mklink', '/d', path2str(orig), path2str(dest)], shell=True)
    else:
        orig.symlink_to(dest)

to

def symlink_to(orig, dest):
    if (is_python2 or is_python3) and is_windows:
        import subprocess
        subprocess.call(['mklink', '/d', path2str(orig), path2str(dest)], shell=True)
    else:
        orig.symlink_to(dest)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugBugs and behaviour differing from documentationfeat / cliFeature: Command-line interface

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions