ImportError:您正在使用的"scipy"安装似乎已损坏,(无法导入扩展模块),请尝试重新安



当我试图通过Jupyter笔记本在Python3.9中使用scipy或sklearn包时,我经常收到这个错误。

错误为:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
~/opt/anaconda3/lib/python3.9/site-packages/scipy/__init__.py in <module>
165     try:
--> 166         from scipy._lib._ccallback import LowLevelCallable
167     except ImportError as e:
~/opt/anaconda3/lib/python3.9/site-packages/scipy/_lib/_ccallback.py in <module>
----> 1 from . import _ccallback_c
2 
3 import ctypes
ImportError: dlopen(/Users/dn/opt/anaconda3/lib/python3.9/site-packages/scipy/_lib/_ccallback_c.cpython-39-darwin.so, 0x0002): tried: '/Users/dn/opt/anaconda3/lib/python3.9/site-packages/scipy/_lib/_ccallback_c.cpython-39-darwin.so' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64'))
The above exception was the direct cause of the following exception:
ImportError                               Traceback (most recent call last)
/var/folders/d7/q_fznsr95_97r6lp_mx_vp640000gn/T/ipykernel_37825/912110602.py in <module>
1 #import scipy
----> 2 from sklearn.ensemble import RandomForestClassifier #Picks up non-linearities
~/opt/anaconda3/lib/python3.9/site-packages/sklearn/__init__.py in <module>
80     from . import _distributor_init  # noqa: F401
81     from . import __check_build  # noqa: F401
---> 82     from .base import clone
83     from .utils._show_versions import show_versions
84 
~/opt/anaconda3/lib/python3.9/site-packages/sklearn/base.py in <module>
15 from . import __version__
16 from ._config import get_config
---> 17 from .utils import _IS_32BIT
18 from .utils._tags import (
19     _DEFAULT_TAGS,
~/opt/anaconda3/lib/python3.9/site-packages/sklearn/utils/__init__.py in <module>
20 import warnings
21 import numpy as np
---> 22 from scipy.sparse import issparse
23 
24 from .murmurhash import murmurhash3_32
~/opt/anaconda3/lib/python3.9/site-packages/scipy/__init__.py in <module>
169               "(extension modules cannot be imported), " + 
170               "please try reinstalling."
--> 171         raise ImportError(msg) from e
172 
173     from scipy._lib._testutils import PytestTester
ImportError: The `scipy` install you are using seems to be broken, (extension modules cannot be imported), please try reinstalling.

我尝试过卸载和重新安装scipy,正如文档中所描述的那样,也尝试过使用自制软件,但仍然出现了同样的错误。

有人知道如何解决这个问题吗?Scipy几周前还在我的机器上工作——不确定过去几周发生了什么变化。

非常感谢您的帮助。

对我来说,这是由于防病毒,删除了scipy文件的appdata副本。检查是否有文件_ccallbcak_cp310-win_amd64.pyd从c:\Users\XXXX\AppData\Roaming\Python\Python310\site packages\scipy_lib 被阻止

我也面临同样的问题,但重新安装对我来说很有效。使用Anaconda(或Miniconda(卸载并安装scipy

pip uninstall scipy
pip install scipy

在调试过程中,我还升级了pip并安装了spider,也许它们包含了任何对我有帮助的软件包

相关内容

  • 没有找到相关文章

最新更新