gpt4 book ai didi

python - 导入 nltk 包时如何解决以下错误

转载 作者:行者123 更新时间:2023-12-04 17:10:16 27 4
gpt4 key购买 nike

Screenshot of the error
使用 pip3 install nltk 安装 nltk 后
我无法在 macOS 的 python shell 中导入 nltk


File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/nltk/__init__.py", line 137, in <module>

from nltk.text import *
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/nltk/text.py", line 29, in <module>

from nltk.tokenize import sent_tokenize
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/nltk/tokenize/__init__.py", line 65, in <module>

from nltk.tokenize.casual import TweetTokenizer, casual_tokenize
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/nltk/tokenize/casual.py", line 49, in <module>

import regex # https://github.com/nltk/nltk/issues/2409
File "/Users/userId/Library/Python/3.9/lib/python/site-packages/regex/__init__.py", line 1, in <module>

from .regex import *
File "/Users/userId/Library/Python/3.9/lib/python/site-packages/regex/regex.py", line 419, in <module>

import regex._regex_core as _regex_core
File "/Users/userId/Library/Python/3.9/lib/python/site-packages/regex/_regex_core.py", line 21, in <module>

import regex._regex as _regex
ImportError: dlopen(/Users/userId/Library/Python/3.9/lib/python/site-packages/regex/_regex.cpython-39-darwin.so, 2): no suitable image found. Did find:
/Users/userId/Library/Python/3.9/lib/python/site-packages/regex/_regex.cpython-39-darwin.so: code signature in (/Users/userId/Library/Python/3.9/lib/python/site-packages/regex/_regex.cpython-39-darwin.so) not valid for use in process using Library Validation: Trying to load an unsigned library```

最佳答案

刚遇到这个,我发现以下解决了它:

xcrun codesign --sign - "[YOUR_PATH_TO_DYLIB_HERE]"
在我的情况下,错误是这样的:
ImportError: dlopen(/Users/USER/dev/cr-likes/venv/lib/python3.9/site-packages/regex/_regex.cpython-39-darwin.so, 2): no suitable image found.  Did find:
/Users/USER/dev/cr-likes/venv/lib/python3.9/site-packages/regex/_regex.cpython-39-darwin.so: code signature in (/Users/USER/dev/cr-likes/venv/lib/python3.9/site-packages/regex/_regex.cpython-39-darwin.so) not valid for use in process using Library Validation: Trying to load an unsigned library
通过运行 xcrun在共享对象上,在本例中 /Users/USER/dev/cr-likes/venv/lib/python3.9/site-packages/regex/_regex.cpython-39-darwin.so现在错误消失了。

关于python - 导入 nltk 包时如何解决以下错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69610572/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com