Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...