简体   繁体   English

尝试导入cv的“ DLL加载失败”(从OpenCV-python)

[英]“DLL load failed” trying to import cv (from OpenCV-python)

When I try to execute import cv , the following error is raised: 当我尝试执行import cv ,引发以下错误:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: DLL load failed: The specified module could not be found.

I have installed it using pip install OpenCV-python also tried by installing from sourceforge.net (recent one) later copied cv2.pyd from build\\python\\x64 and pasted it in python 36\\Lib\\site-packages . 我已经使用pip install OpenCV-python安装了它,也尝试从sourceforge.net (最近一个)进行安装,后来从build\\python\\x64复制cv2.pyd并将其粘贴到python 36\\Lib\\site-packages I work on windows 10 64-bit 我在Windows 10 64位上工作

This error means your Python environment is unable to find the OpenCV module. 此错误意味着您的Python环境无法找到OpenCV模块。 You need to tell Python where to find it. 您需要告诉Python在哪里找到它。 Just to make things easier, use python 2 to run your script (python instead of python3) and try python 3 after python 2 works. 为了使事情变得更简单,请使用python 2运行脚本(使用python代替python3),然后在python 2工作之后尝试使用python 3。

  1. (Optional) Restart the system, just in case your system hasn't updated environment variables. (可选)重新启动系统,以防万一您的系统尚未更新环境变量。 Windows needs this. Windows需要这个。
  2. Find the directory where you installed OpenCV. 找到您安装OpenCV的目录。 If you have multiple installations, please uninstall everything and install only 1, and make sure you take note of the installation directory. 如果您有多个安装,请卸载所有内容并仅安装1,并确保记下安装目录。
  3. Go to that installation directory, and in the subdirectory that contains the built files, search for the python module. 转到该安装目录,然后在包含已构建文件的子目录中搜索python模块。 It might look similar to this: C:\\opencv\\build\\python\\3.4.1 but it changes depending on your installation method. 它看起来可能类似于:C:\\ opencv \\ build \\ python \\ 3.4.1,但它会根据您的安装方法而变化。
  4. We need to set an environment variable. 我们需要设置一个环境变量。 Usually you go to Control Panel -> System and Security -> System and then click on the "Advanced system settings" link, then click on the "Environment variables" button near the bottom of the menu. 通常,您进入“控制面板”->“系统和安全性”->“系统”,然后单击“高级系统设置”链接,然后单击菜单底部附近的“环境变量”按钮。 This might change depending on your Windows version, but you can easily google this. 这可能会根据您的Windows版本而改变,但是您可以轻松地用Google搜索。
  5. Look for a variable called PYTHONPATH. 查找一个名为PYTHONPATH的变量。 If you have it we'll append something to it, otherwise click the "New.." button under System for all users or User variables (for your account only) and for "Variable name" enter: "PYTHONPATH". 如果您有它,我们将添加一些内容,否则,对所有用户或用户变量(仅对于您的帐户),单击“系统”下的“新建..”按钮,对于“变量名”,输入:“ PYTHONPATH”。
  6. Set the "Variable value" to the path you found in (2). 将“变量值”设置为您在(2)中找到的路径。 If appending to an existing variable, make sure paths are separated by ; 如果附加到现有变量,请确保路径之间用;分隔;
  7. Restart the system. 重新启动系统。 import cv should work now. import cv现在应该可以工作了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM