Python下ImportError: DLL load failed: 找不到指定的模块之问题分析
程序员文章站
2022-03-20 13:17:34
...
环境依赖
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
- 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的界面了。
总结
这种问题比较难以侦测和修复,主要无法感知其具体的问题根源,默认可以升级至最新版本。
参考资料
推荐阅读
-
Windows环境下Python3.6.8 importError: DLLload failed:找不到指定的模块
-
import tensroflow时出现了ImportError: DLL load failed: 找不到指定的模块的解决办法
-
Python自动发邮件以及打包报错failed to execute script和DLL load failed while importing win32api: 找不到指定的模块
-
PySide2出现“ImportError: DLL load failed: 找不到指定的模块”的问题及解决方法
-
ImportError: DLL load failed: 找不到指定的模块。
-
tf2在import时报出ImportError: DLL load failed: 找不到指定的模块
-
ImportError: DLL load failed: 找不到指定的模块
-
Python下ImportError: DLL load failed: 找不到指定的模块之问题分析
-
python导包出现:ImportError: DLL load failed: 找不到指定的模块问题解决
-
ImportError: DLL load failed: 找不到指定的模块