python2.7 + opencv-python3.4.5.20 + pyinstaller3.6,DLL load failed

在写完cv2相关应用,打包发布到服务器部署的时候,出现了问题(python,opencv,pyinstaller相关版本)。

>pip show opencv-python
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
Name: opencv-python
Version: 3.4.5.20
Summary: Wrapper package for OpenCV python bindings.
Home-page: https://github.com/skvark/opencv-python
Author: None
Author-email: None
License: MIT
Location: d:\develtools\python27\lib\site-packages
Requires: numpy
Required-by:

>pyinstaller -v
3.6

# pip install requests
# pip install pywin32
# pip install flask
# pip install opencv-python
# pyinstaller -F opencvtest.py

打包后,在服务器安装部署的时候,出现下面的问题:

>opencvtest.exe
Traceback (most recent call last):
  File "opencvtest.py", line 7, in <module>
  File "d:\develtools\python27\lib\site-packages\PyInstaller-3.6-py2.7.egg\PyIns
taller\loader\pyimod03_importers.py", line 391, in load_module
  File "site-packages\cv2\__init__.py", line 3, in <module>
  File "d:\develtools\python27\lib\site-packages\PyInstaller-3.6-py2.7.egg\PyIns
taller\loader\pyimod03_importers.py", line 680, in load_module
ImportError: DLL load failed: 找不到指定的模块。
[5448] Failed to execute script opencvtest

通过depends查看,缺少api-ms-win-downlevel-advapi32-l1-1-0.dllapi-ms-win-downlevel-advapi32-l1-1-0.dllapi-ms-win-downlevel-shlwapi-l1-1-0.dllmsIso.dll,这些问题可以通过下面安装桌面体验解决:

  • windows 2008 打开服务器管理器,右上角点“管理”-->添加角色和功能。点“服务器选择”-->“功能”,拖动条拖到最下面,勾选“桌面体验”,点“安装”按钮

  • windows 2012 打开服务器管理器,右上角点“管理”-->添加角色和功能。点“服务器选择”-->“功能”,拖动条拖到最下面,点开“用户界面和基础结构”,勾选“桌面体验”,点“安装”按钮

安装完,重启服务器,问题解决


标签:opencv-python pyinstaller cv2