Python下ImportError: DLL load failed: 找不到指定的模块之问题分析

环境依赖

OS: window 7, python 3.6 Anaconda: 5.0.1

问题的提出

在运行Python代码的时候,碰到了如下问题:

runfile('D:/code/test.py', wdir='D:/code')
Traceback (most recent call last):

  File "<ipython-input-4-f0247c595423>", line 1, in <module>
    runfile('D:/code/test.py', wdir='D:/code')

  File "d:\ProgramData\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 705, in runfile
    execfile(filename, namespace)

  File "d:\ProgramData\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "D:/BaiduNetdiskDownload/第十周/程序/10-3-验证码识别.py", line 8, in <module>
    from PIL import Image

  File "d:\ProgramData\Anaconda3\lib\site-packages\PIL\Image.py", line 56, in <module>
    from . import _imaging as core

ImportError: DLL load failed: 找不到指定的模块

经过检查Pillow都已经安装,且版本为4.2.1 [pillow: 4.2.1-py36hdb25ab2_0]。
感觉问题是Pillow或者Pillow的依赖库的安装不完整造成的,因为dll没有找到。

问题的查找

查找了一番资料之后,找到了一个解决方案:

  • conda uninstall pillow
  • conda update pip
  • pip install pillow
    从上述指令分析可知,conda中pillow的版本估计比较老或者有问题,需要使用pip库中的pillow包,且需要安装其最新版本的包。
    基本的操作如下:

    关闭anaconda,执行指令conda uninstall pillow

指令输出结果信息:

Solving environment: done
==> WARNING: A newer version of conda exists. <==
  current version: 4.4.6
  latest version: 4.4.11

Please update conda by running
    $ conda update -n base conda

-- Package Plan --

  environment location: D:\ProgramData\Anaconda3

  removed specs:
    - pillow


The following packages will be REMOVED:

    anaconda-navigator: 1.6.12-py36hdad2993_0
    pillow:             4.2.1-py36hdb25ab2_0
    scikit-image:       0.13.0-py36h6dffa3f_1

Proceed ([y]/n)? y

Preparing transaction: done
Verifying transaction: done
Executing transaction: \ DEBUG menuinst_win32:__init__(185): Menu: name: 'Anaconda${PY_VER} ${PLATFORM}', prefix: 'D:\ProgramData\Anaconda3', env_name: 'None', mode: 'None', used_mode: 'system'
DEBUG menuinst_win32:create(299): Shortcut cmd is D:\ProgramData\Anaconda3\pythonw.exe, args are ['D:\\ProgramData\\Anaconda3\\cwp.py', 'D:\\ProgramData\\Anaconda3', 'D:\\ProgramData\\Anaconda3\\pythonw.exe', 'D:\\ProgramData\\Anaconda3\\Scripts\\anaconda-navigator-script.py']
done

conda update pip # 升级 pip

指令升级内容输出如下:

Solving environment: done


==> WARNING: A newer version of conda exists. <==
  current version: 4.4.6
  latest version: 4.4.11

Please update conda by running

    $ conda update -n base conda



## Package Plan ##

  environment location: D:\ProgramData\Anaconda3

  added / updated specs:
    - pip


The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    pip-9.0.1                  |           py36_5         2.5 MB

The following packages will be UPDATED:

    pip: 9.0.1-py36hadba87b_3 --> 9.0.1-py36_5

Proceed ([y]/n)? y


Downloading and Extracting Packages
pip 9.0.1: ######################################################################################################################################################################### | 100%
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
  1. pip install pillow
    指令升级输出内容如下:
Collecting pillow
  Using cached Pillow-5.0.0-cp36-cp36m-win_amd64.whl
Installing collected packages: pillow
Successfully installed pillow-5.0.0
You are using pip version 9.0.1, however version 9.0.2 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

由上文可知,pillow的版本从4.2.1 升级到了5.0.0的版本。

问题的解决

重新执行一下程序,dll找不到的问题已经被修复了。

接着把之前卸载的anaconda-navigator安装一下:

conda install anaconda-navigator

结果输出信息如下:

Solving environment: done


==> WARNING: A newer version of conda exists. <==
  current version: 4.4.6
  latest version: 4.4.11

Please update conda by running

    $ conda update -n base conda



## Package Plan ##

  environment location: D:\ProgramData\Anaconda3

  added / updated specs:
    - anaconda-navigator


The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    anaconda-navigator-1.7.0   |           py36_0         4.3 MB
    pillow-5.0.0               |   py36h0738816_0         624 KB
    ------------------------------------------------------------
                                           Total:         4.9 MB

The following NEW packages will be INSTALLED:

    anaconda-navigator: 1.7.0-py36_0
    pillow:             5.0.0-py36h0738816_0

Proceed ([y]/n)? y


Downloading and Extracting Packages
anaconda-navigator 1.7.0: ########################################################################################################################################################## | 100%
pillow 5.0.0: ###################################################################################################################################################################### | 100%
Preparing transaction: done
Verifying transaction: done
Executing transaction: \ DEBUG menuinst_win32:__init__(185): Menu: name: 'Anaconda${PY_VER} ${PLATFORM}', prefix: 'D:\ProgramData\Anaconda3', env_name: 'None', mode: 'None', used_mode: 'system'
DEBUG menuinst_win32:create(299): Shortcut cmd is D:\ProgramData\Anaconda3\pythonw.exe, args are ['D:\\ProgramData\\Anaconda3\\cwp.py', 'D:\\ProgramData\\Anaconda3', 'D:\\ProgramData\\Anaconda3\\pythonw.exe', 'D:\\ProgramData\\Anaconda3\\Scripts\\anaconda-navigator-script.py']
done

然后就重新可以打开Anaconda的界面了。

总结

这种问题比较难以侦测和修复,主要无法感知其具体的问题根源,默认可以升级至最新版本。

参考资料

  1. http://blog.csdn.net/m0_37422289/article/details/79284541
已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 创作都市 设计师:CSDN官方博客 返回首页