0

我是使用 stackoverflow 的新手,所以欢迎任何关于更清楚地提问的建议。

我正在尝试使用原子中的氢在 mac M1 芯片上运行 python 脚本,这在过去对我有用。擦拭干净的笔记本电脑后,它不再起作用。我收到以下错误:

对于 numpy,我得到以下信息:“导入 numpy C 扩展失败。发生此错误的原因有很多,通常是由于您的设置或 NumPy 的安装方式存在问题。” ...

Original error was: dlopen(/Users/user/Library/Python/3.8/lib/python/site-packages/numpy/core/_multiarray_umath.cpython-38-darwin.so, 0x0002): tried: '/Users/user/Library/Python/3.8/lib/python/site-packages/numpy/core/_multiarray_umath.cpython-38-darwin.so' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64')), '/usr/local/lib/_multiarray_umath.cpython-38-darwin.so' (no such file), '/usr/lib/_multiarray_umath.cpython-38-darwin.so' (no such file)

然后,对于 nltk:

dlopen(/Users/user/Library/Python/3.8/lib/python/site-packages/regex/_regex.cpython-38-darwin.so, 0x0002): tried: '/Users/user/Library/Python/3.8/lib/python/site-packages/regex/_regex.cpython-38-darwin.so' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64')), '/usr/local/lib/_regex.cpython-38-darwin.so' (no such file), '/usr/lib/_regex.cpython-38-darwin.so' (no such file)

我已经按照我可以在网上找到的所有教程进行操作,但没有运气。

如果有帮助,我的 jupyter 和 python 路径分别如下:

/usr/local/share, /usr/bin/python3

此外,我的 python 和 numpy 版本是最新的并且是我期望的版本。

4

1 回答 1

0

我使它工作的方式是在我的 .py 文件的顶部添加:

import sys
sys.path.append('/Users/[username]/opt/anaconda3/envs/[your_virtual_env_name]/lib/python3.10/site-packages')

我将答案中的解决方案和Tell Atom+Hydrogen 的评论结合起来,在虚拟环境中查找包

于 2022-03-03T16:37:13.650 回答