Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
320 views
in Technique[技术] by (71.8m points)

python - ModuleNotFoundError: No module named: openCV

I have installed opencv for example, and when importing in sublimetext or in a terminal I jump "ModuleNotFoundError: No module named". If I do it from the python idle, it does not

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I reproduced your error and was able to fix it as following:

This error often happens when you did not added your Python path correctly.

To check wether your python is installed an configured correctly go to your terminal and type:

python -V 

and then:

pip -v

The two versions have to match.

Also simply run:

python 

and check wether an interactive shell opens. If your versions are matching and the the python command works, your python is configured correctly and you can skip the next step. If not follow the steps below, if everthing works skip this:

For Windows try this: https://superuser.com/questions/143119/how-do-i-add-python-to-the-windows-path

For Mac OS try this:

export PATH=~/path/to/your/python/bin:$PATH

For example:

export PATH=~/anaconda2/bin:$PATH

Now the next thing...

CV2 has two prerequisites there for run:

pip install matplotlib
pip install numpy

and finally:

pip install opencv-python

Now you are ready to go an you can import opencv in your code as following:

import cv2

When you are using pyhton3 use:

python3 test.py

to run your code.

If you want to use python instead of python3 do this:

The last Python you install that registers itself in the environment is the default.

If you would like to have Python 3.x as a default version, then you will need to create environment variable 'PY_PYTHON' and set it's value to 3


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...