我遇到了一个有趣的错误,我可以在终端上的Ipython中import cv2
,但无法在Jupyter笔记本上导入库。我检查了内核,但我使用相同的内核(Anaconda python2.7)
有人知道如何解决这个问题吗?
Error:
ImportErrorTraceback (most recent call last)
<ipython-input-2-52da0154cfe4> in <module>()
----> 1 import cv2
2 import numpy as np
ImportError: No module named cv2
$ import os
$ os.sys.path
['',
'/Users/kn/anaconda2/envs/python2/lib/python27.zip',
'/Users/kn/anaconda2/envs/python2/lib/python2.7',
'/Users/kn/anaconda2/envs/python2/lib/python2.7/plat-darwin',
'/Users/kn/anaconda2/envs/python2/lib/python2.7/plat-mac',
'/Users/kn/anaconda2/envs/python2/lib/python2.7/plat-mac/lib-scriptpackages',
'/Users/kn/anaconda2/envs/python2/lib/python2.7/lib-tk',
'/Users/kn/anaconda2/envs/python2/lib/python2.7/lib-old',
'/Users/kn/anaconda2/envs/python2/lib/python2.7/lib-dynload',
'/Users/kn/anaconda2/envs/python2/lib/python2.7/site-packages',
'/Users/kn/anaconda2/envs/python2/lib/python2.7/site-packages/Sphinx-1.4.6-py2.7.egg',
'/Users/kn/anaconda2/envs/python2/lib/python2.7/site-packages/aeosa',
'/Users/kn/anaconda2/envs/python2/lib/python2.7/site-packages/setuptools-27.2.0-py2.7.egg',
'/Users/kn/anaconda2/envs/python2/lib/python2.7/site-packages/IPython/extensions',
'/Users/kn/.ipython']
$ python
/Users/kn/anaconda2/envs/python2/bin/python
答案 0 :(得分:0)
在opencv.pth
下创建一行/Users/kn/anaconda2/lib/python2.7/site-packages
文件。
该文件的内容如下:
/usr/local/opt/opencv3/lib/python2.7/site-packages
这将永久地在所有conda环境下附加opencv3
路径。我认为这比为python2
环境提供cv2更好。