我在Windows 10下使用Visual Studio 2017从源代码构建了OpenCV 3.2,它在构建目录中生成了一个文件cv2.cp36-win_amd64.pyd
,并将其复制到C:\Users\fanta\Anaconda3\Lib\site-packages
。
但是现在,在进入Python 3.6的Anaconda环境后,python找不到包,请参阅下面的脚本(底部错误):
C:\Users\fanta>conda create -n py36 python=3.6
Fetching package metadata ...........
Solving package specifications: .
Package plan for installation in environment C:\Users\fanta\Anaconda3\envs\py36:
The following NEW packages will be INSTALLED:
pip: 9.0.1-py36_1
python: 3.6.1-2
setuptools: 27.2.0-py36_1
vs2015_runtime: 14.0.25123-0
wheel: 0.29.0-py36_0
Proceed ([y]/n)?
#
# To activate this environment, use:
# > activate py36
#
# To deactivate this environment, use:
# > deactivate py36
#
# * for power-users using bash, you must source
#
C:\Users\fanta>activate py36
(py36) C:\Users\fanta>python
Python 3.6.1 |Continuum Analytics, Inc.| (default, May 11 2017, 13:25:24) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'cv2'
>>>
如果我尝试从任何Anaconda环境外部导入cv2
包,我会收到不同的错误,请参阅下文:
(py36) C:\Users\fanta>deactivate py36
C:\Users\fanta>python
Python 3.6.0 |Anaconda 4.3.1 (64-bit)| (default, Dec 23 2016, 11:57:41) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: DLL load failed: The specified module could not be found.
>>>
如何在Anaconda环境中导入构建的cv2
包?
谢谢!
答案 0 :(得分:0)
原来py36
文件的正确位置(对于我的C:\Users\fanta\Anaconda3\envs\py36\Lib
Anaconda环境):
ImportError: DLL load failed: The specified module could not be found.
然后我得到了C:\opencv32\build\install\x64\vc15\bin
修复ImportError:
C:\opencv32\build\install\x64\vc15
在我的
情况下); (name + "\t" + socialNum + "\t" + cellNum + "\t" + tickNum + "\n")
情况)。最后我在Anaconda环境中安装了numpy和matplotlib。
现在使用Visual Studio 2017从源代码构建的OpenCV 3.2可以正常工作。