尝试运行python包时出现“RuntimeError:无效插槽偏移量”

2024-04-28 10:22:44 发布

您现在位置:Python中文网/ 问答频道 /正文

我对一直运行的脚本使用pyhyphen包。最近,我更新了MacOS Big Sur。Spyder很落后,但我通过运行一个虚拟环境和pip install我需要的东西来解决这个问题。没有问题

现在,当我尝试运行from hyphen import Hyphenatorhere is the package page)时,出现以下错误:

[autoreload of hyphen.dictools failed: Traceback (most recent call last):
  File "/Users/myname/anaconda3/lib/python3.8/site-packages/IPython/extensions/autoreload.py", line 245, in check
    superreload(m, reload, self.old_objects)
  File "/Users/myname/anaconda3/lib/python3.8/site-packages/IPython/extensions/autoreload.py", line 394, in superreload
    module = reload(module)
  File "/Users/myname/anaconda3/lib/python3.8/imp.py", line 314, in reload
    return importlib.reload(module)
  File "/Users/myname/anaconda3/lib/python3.8/importlib/__init__.py", line 159, in reload
    raise ImportError(msg.format(parent_name),
ImportError: parent 'hyphen' not in sys.modules
]


runcell(0, '/Users/myname/Documents/project/project.py')
Traceback (most recent call last):

  File "/Users/myname/Documents/project/project.py", line 17, in <module>
    from hyphen import Hyphenator

  File "/Users/myname/anaconda3/lib/python3.8/site-packages/hyphen/__init__.py", line 10, in <module>
    from .hyphenator import Hyphenator

  File "/Users/myname/anaconda3/lib/python3.8/site-packages/hyphen/hyphenator.py", line 27, in <module>
    from . import hnj

RuntimeError: invalid slot offset

from hyphen import Hyphenator是脚本中唯一的一行。我已经尝试卸载/重新安装该软件包600次了,但我找不到任何解决方案。所有其他软件包导入良好,没有问题

Spyder(在Anaconda中)正在运行python版本3.8.5。我安装了non-anaconda 3.9,但我无法想象这会有任何效果,因为我在虚拟环境中运行spyder


Tags: infrompyimportliblinesiteusers
2条回答

我建议您通过anaconda而不是pip安装:

source /Users/myname/anaconda3/bin/activate
conda install -c auto pyhyphen

安装软件包时似乎出现了问题

ext_modules=[
        Extension('hyphen.hnj', ['lib/hnjmodule.c',
                                 'lib/hyphen.c',
                                 'lib/hnjalloc.c'],
                  include_dirs=['lib'],
                  py_limited_api=True)
                  ],

程序包hnj未正确编译

尝试手动安装并生成包

相关问题 更多 >