简体   繁体   English

Anaconda找不到模块cv2

[英]Anaconda doesn't find module cv2

I am using Anaconda on OS X Mavericks. 我在OS X Mavericks上使用Anaconda。 When I try loading cv2 I get an import error (see below). 当我尝试加载cv2我收到导入错误(见下文)。 Do you know how to fix this? 你知道怎么解决这个问题吗?

>>import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: dlopen(/usr/local/Cellar/opencv/2.4.8.2/lib/python2.7/site-packages/cv2.so,    
2): Library not loaded: /usr/local/lib/libpng15.15.dylib
Referenced from: /usr/local/Cellar/opencv/2.4.8.2/lib/libopencv_highgui.2.4.dylib
Reason: image not found

I am not sure it's relevant, but in /usr/local/lib/ I have libpng16.16.dylib instead of libpng15.15.dylib . 我不确定它是否相关,但在/usr/local/lib/我有libpng16.16.dylib而不是libpng15.15.dylib

This is the solution I found: 这是我找到的解决方案:

作为建议这个问题,我简单地执行固定的这个问题

conda update hdf5

you could also just add it to your PYTHONPATH. 你也可以把它添加到你的PYTHONPATH。 here's how: you should be able to get it to load through one of the other (non anaconda) python executables. 这是如何:你应该能够通过其他(非anaconda)python可执行文件加载它。 mine were located at: /usr/bin/python (default system python) and /usr/local/bin/python (brew) 我的位于:/ usr / bin / python(默认系统python)和/ usr / local / bin / python(brew)

  • call the python executable using the full path 使用完整路径调用python可执行文件
  • once you successfully import cv2 run: cv2.__file__ this will give you the file's path which you can then take (full directory path not including filename) and add as the first argument to your PYTHONPATH defined in ~/.bash_profile 一旦你成功导入cv2 run:cv2 .__ file__,这将为你提供文件的路径,然后你可以使用(完整的目录路径不包括文件名),并添加为〜/ .bash_profile中定义的PYTHONPATH的第一个参数
  • after changing the .bash_profile don't forget to run source ~/.bash_profile to make the changes effective 更改.bash_profile之后不要忘记运行source~ / .bash_profile以使更改生效
  • fire up anaconda python and it should now find cv2 启动anaconda python,它现在应该找到cv2

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

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