Import from ipython

2019-07-20 09:36发布

If I use IDLE with python 2.7

import cv
import cv2

and it works

but if I use ipython notebook

it gives me error

ImportError Traceback (most recent call last) in () ----> 1 import cv

ImportError: No module named cv

So how to use OpenCV from iPython?

EDIT:

from IDLE

['', 'C:\Python27\Lib\idlelib', 'C:\Python27\lib\site-packages\pip-1.1-py2.7.egg', 'C:\Python27\lib\site-packages\gensim-0.8.6-py2.7.egg', 'C:\WINDOWS\system32\python27.zip', 'C:\Python27\DLLs', 'C:\Python27\lib', 'C:\Python27\lib\plat-win', 'C:\Python27\lib\lib-tk', 'C:\Python27', 'C:\Python27\lib\site-packages', 'C:\Python27\lib\site-packages\PIL']

from ipython anaconda

['', 'C:\Anaconda\python27.zip', 'C:\Anaconda\DLLs', 'C:\Anaconda\lib', 'C:\Anaconda\lib\plat-win', 'C:\Anaconda\lib\lib-tk', 'C:\Anaconda', 'C:\Anaconda\lib\site-packages', 'C:\Anaconda\lib\site-packages\PIL', 'C:\Anaconda\lib\site-packages\win32', 'C:\Anaconda\lib\site-packages\win32\lib', 'C:\Anaconda\lib\site-packages\Pythonwin', 'C:\Anaconda\lib\site-packages\setuptools-0.6c11-py2.7.egg-info', 'C:\Anaconda\lib\site-packages\IPython\extensions']

so the questions seems to be how to install opencv in ipython anaconda? (and why it doesn't use standard python packages)

1条回答
Explosion°爆炸
2楼-- · 2019-07-20 09:43

is your PYTHONPATH different in ipython and IDLE? try the following

import sys
print(sys.path)

I suspect the two won't match. have you launched IDLE and ipython from the same terminal?

查看更多
登录 后发表回答