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

时间:2019-12-06 03:20:52

标签: python django python-3.x python-2.7 scikit-learn

我试图从resample_img导入nilearn.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.

有什么想法吗?

2 个答案:

答案 0 :(得分:1)

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

在安装“ Visual Studio 2019的Microsoft Visual C ++可再发行组件”并重新启动后,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

答案 1 :(得分:0)

您的nilearn似乎取决于sklearn。问题是由于缺少_openmp_helpers.py文件而在导入pipsklearn在其中寻找文件。

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

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

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