0

After installing Opencv for Python 3, I went on to try installing Opencv for python 2. I had a lot of trouble searching for the problem then after using dependency walker and downloading the missing dll, it worked. However IDLE for Python 3 gave me this message.

Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:06:47) [MSC v.1914 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> import cv
Traceback (most recent call last):
  File "<pyshell#0>", line 1, in <module>
    import cv
  File "C:\Python37\lib\site-packages\cv.py", line 1, in <module>
    from cv2.cv import *
  File "C:\Python37\lib\site-packages\cv2\__init__.py", line 3, in <module>
    from .cv2 import *
ImportError: DLL load failed: The specified module could not be found.
>>> import cv2
Traceback (most recent call last):
  File "<pyshell#1>", line 1, in <module>
    import cv2
  File "C:\Python37\lib\site-packages\cv2\__init__.py", line 3, in <module>
    from .cv2 import *
ImportError: DLL load failed: The specified module could not be found.
>>> 

Edit: I think I may have to downgrade my Python 3 version. I am still open to suggestions though!

2
  • use conda to manage different env Commented Feb 1, 2019 at 22:16
  • is it possible to do without conda? It worked before without it, I am just wondering if it's because i didn't set any PATH Commented Feb 1, 2019 at 22:18

1 Answer 1

1

According to the PyPi repository, opencv is available for many versions of Python from 2.7 to 3.7. So, yes you can install it twice for Python 2.7 and 3.7 (if it is available for your OS).

But you need to have two Python environments, a.k.a. Virtualenvs! Of course Conda can solve this problem but you can also use the virtualenv tools. Follow the instructions to install it. It is a requirement for Python 2.

Choose a directory to store your virtualenvs, for Instance ~/virtualenv in your HOME. Create it if necessary.

For Python 2.7, you can run:

cd ~/virtualenv
virtualenv -p /path/to/python2 py2-demo
source py2-demo/bin/activate
pip install opencv-python

For Python > 3.3, you can use the venv module:

cd ~/virtualenv
python3 -m venv py3-demo
source py3-demo/bin/activate
pip install opencv-python
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks a lot! I appreciate the advice haha. I will try this out.
did it work for you? I tried to install opencv on my RPi and the funny thing is it installed it on my python2, whereas I needed it on python3 and my python 3 is the default one. I dunno how to fix that problem. I am not sure if venv will work on python too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.