“ImportError:导入 _openmp_helpers 时 DLL 加载失败”?

Posted

技术标签:

【中文标题】“ImportError:导入 _openmp_helpers 时 DLL 加载失败”?【英文标题】:"ImportError: DLL load failed while importing _openmp_helpers"? 【发布时间】:2020-03-31 01:09:57 【问题描述】:

我尝试从nilearn.image 导入resample_img 以用于重新采样一些医学图像。

import nibabel as nib
import nibabel.processing
from nilearn.image import resample_img

img = nib.load('./dicom_to_nifti.nii')
new_img = nibabel.processing.resample_to_output(img, (2, 2, 2))
new_img.to_filename('nifti_2_2_2')

但是我不断收到这个错误,说它找不到 sklearn 模块?我已经通过pip install sklearn 安装了它。我什至尝试卸载所有内容并重新安装,但出现了同样的问题。我确定是我做错了什么,或者包裹有问题。

Traceback (most recent call last):
  File "convert.py", line 9, in <module>
    from nilearn.image import resample_img
    _check_module_dependencies()
  File "C:\Users\craig\AppData\Local\Programs\Python\Python38\lib\site-packages\nilearn\version.py", line 111, in _check_module_dependencies
    _import_module_with_version_check(
  File "C:\Users\craig\AppData\Local\Programs\Python\Python38\lib\site-packages\nilearn\version.py", line 60, in _import_module_with_version_check
    module = __import__(module_name)
  File "C:\Users\craig\AppData\Local\Programs\Python\Python38\lib\site-packages\sklearn\__init__.py", line 75, in <module>
    from .utils._show_versions import show_versions
  File "C:\Users\craig\AppData\Local\Programs\Python\Python38\lib\site-packages\sklearn\utils\_show_versions.py", line 12, in <module>
    from ._openmp_helpers import _openmp_parallelism_enabled
ImportError: DLL load failed while importing _openmp_helpers: The specified module could not be found.. Module "sklearn" could not be found. See http://nilearn.github.io/introduction.html#installation for installation information.
PS C:\Users\craig\Documents\Files\westmead_radiomics> python test.py
Traceback (most recent call last):
  File "test.py", line 3, in <module>
    from nilearn.image import resample_img
  File "C:\Users\craig\AppData\Local\Programs\Python\Python38\lib\site-packages\nilearn\__init__.py", line 72, in <module>
    _check_module_dependencies()
  File "C:\Users\craig\AppData\Local\Programs\Python\Python38\lib\site-packages\nilearn\version.py", line 111, in _check_module_dependencies
    _import_module_with_version_check(
  File "C:\Users\craig\AppData\Local\Programs\Python\Python38\lib\site-packages\nilearn\version.py", line 60, in _import_module_with_version_check
    module = __import__(module_name)
  File "C:\Users\craig\AppData\Local\Programs\Python\Python38\lib\site-packages\sklearn\__init__.py", line 75, in <module>
    from .utils._show_versions import show_versions
  File "C:\Users\craig\AppData\Local\Programs\Python\Python38\lib\site-packages\sklearn\utils\_show_versions.py", line 12, in <module>
    from ._openmp_helpers import _openmp_parallelism_enabled
ImportError: DLL load failed while importing _openmp_helpers: The specified module could not be found.. Module "sklearn" could not be found. See http://nilearn.github.io/introduction.html#installation for installation information.

有什么想法吗?

【问题讨论】:

不知道,但看起来与***.com/questions/59206367/…类似的问题。 【参考方案1】:

您的nilearn 似乎依赖于sklearn。问题来自缺少_openmp_helpers.py 文件,在导入sklearnpip 在其中查找它。

我有一个类似的,并通过将sklearn 降级到 0.22 以下来解决它。这需要从 PyPI 存储库中获取它:

https://pypi.org/project/scikit-learn/0.21.3/#files

而且有点麻烦,因为我必须安装 Python 3.7(最新版本似乎可以与 sklearn 0.21.3 一起使用)和一个 C++ 编译器来构建sklearn(但您可以尝试使用.whl 安装而是)。

【讨论】:

成功了,非常感谢!我不必使用 C++ 编译器或任何东西。我刚刚用pip install安装了旧版本,效果很好。【参考方案2】:

我遇到了同样的问题,并遵循了However, import sklearn still gives me error. More details are given below. How do i resolve this? 的建议。

安装“Microsoft Visual C++ Redistributable for Visual Studio 2019”并重新启动后,sklearn 0.22 工作正常。

> python -c "import sklearn; sklearn.show_versions()"

System:
    python: 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AMD64)]
executable: python.exe
   machine: Windows-10-10.0.14393-SP0

Python dependencies:
       pip: 19.3.1
setuptools: 40.8.0
   sklearn: 0.22
     numpy: 1.18.0
     scipy: 1.4.1
    Cython: None
    pandas: 0.25.3
matplotlib: 3.1.2
    joblib: 0.14.1

Built with OpenMP: True

【讨论】:

它将在 scikit-learn 0.22.1 中解决,但与此同时,这是可能的修复之一(另一个是从 conda-forge 频道安装)

以上是关于“ImportError:导入 _openmp_helpers 时 DLL 加载失败”?的主要内容,如果未能解决你的问题,请参考以下文章