首页 > 解决方案 > 如何安装 spacy 并避免 32/64 位错误?

问题描述

我试图执行

pip install spacy

它最终与 Python 3.7 64 位(不是 32 位版本)一起工作,但安装后没有其他包导入,如 pandas 正在工作。似乎安装是根本原因,但删除 spacy 后,pandas 和许多其他包的导入错误仍然相同。

重新安装 python 后(我总是直接将它安装在文件夹 C:\Python 中),我可以成功安装 pandas 和所有其他包而不会出现以下错误,但我仍然无法使用 Spacy,因为我会收到导入错误:

OSError: [WinError 193] %1 不是有效的 Win32 应用程序

---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
<ipython-input-1-7dd3504c366f> in <module>
----> 1 import pandas as pd

c:\python\lib\site-packages\pandas\__init__.py in <module>
      9 for dependency in hard_dependencies:
     10     try:
---> 11         __import__(dependency)
     12     except ImportError as e:
     13         missing_dependencies.append("{0}: {1}".format(dependency, str(e)))

~\AppData\Roaming\Python\Python37\site-packages\numpy\__init__.py in <module>
    138 
    139     # Allow distributors to run custom init code
--> 140     from . import _distributor_init
    141 
    142     from . import core

~\AppData\Roaming\Python\Python37\site-packages\numpy\_distributor_init.py in <module>
     24                 # NOTE: would it change behavior to load ALL
     25                 # DLLs at this path vs. the name restriction?
---> 26                 WinDLL(os.path.abspath(filename))
     27                 DLL_filenames.append(filename)
     28     if len(DLL_filenames) > 1:

c:\python\lib\ctypes\__init__.py in __init__(self, name, mode, handle, use_errno, use_last_error)
    362 
    363         if handle is None:
--> 364             self._handle = _dlopen(self._name, mode)
    365         else:
    366             self._handle = handle

OSError: [WinError 193] %1 ist keine zulässige Win32-Anwendung´´´



标签: pythonnlpspacy

解决方案


您目前有两个不同的site-package文件夹从中导入包:

c:\python\lib\site-packages

~\AppData\Roaming\Python\Python37\site-packages

在我看来,您的系统上当前混合了不同的 python 安装,或者是以前安装的残留版本,然后是不完全删除的版本。因此,我建议:

  1. 删除所有 python 安装
  2. 完全删除两者c:\python~\AppData\Roaming\Python
  3. 仅重新安装一个 python 发行版。如果您不在乎使用哪个版本,请选择 64 位版本

推荐阅读