python报错ImportError: DLL load failed while importing cv2解决方法

系统:tx云服务器winserver 2012r2

python版本:python3.10.11

import模块时出现DLL load failed while importing cv2

解决方法(适用python3.8-3.10,其它没测试):

打开目录:C:\Users\xxxx\AppData\Local\Programs\Python\Python310\Lib\site-packages\cv2

把__init__.py复制一份副本,然后修改__init__.py内容如下:

import importlib
import os
import sys

from cv2 import *
from .data import *

# wildcard import above does not import "private" variables like __version__
# this makes them available
globals().update(importlib.import_module("cv2").__dict__)

ci_and_not_headless = False

try:
    from .version import ci_build, headless

    ci_and_not_headless = ci_build and not headless
except:
    pass

# the Qt plugin is included currently only in the pre-built wheels
if sys.platform.startswith("linux") and ci_and_not_headless:
    os.environ["QT_QPA_PLATFORM_PLUGIN_PATH"] = os.path.join(
        os.path.dirname(os.path.abspath(__file__)), "qt", "plugins"
    )

# Qt will throw warning on Linux if fonts are not found
if sys.platform.startswith("linux") and ci_and_not_headless:
    os.environ["QT_QPA_FONTDIR"] = os.path.join(
        os.path.dirname(os.path.abspath(__file__)), "qt", "fonts"
    )

修改完后保存就行了。

  • 4
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值