首页 > 解决方案 > “ImportError:导入 _openmp_helpers 时 DLL 加载失败”?

问题描述

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

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.

有任何想法吗?

标签: pythondjangopython-3.xpython-2.7scikit-learn

解决方案


我遇到了同样的问题并遵循了但是 import sklearn 的建议仍然给我错误。更多细节如下。我该如何解决这个问题?.

安装“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

推荐阅读