1

I've created a project in Pycharm IDE. I've used python 3.5, tensorflow library. Now I want to install opencv in this.
I have tried so many videos available on youtube and some tutorials in the internet. But when import open cv in python shell it gives me following error. How can I fix it?
import code

import cv2           

Error message

Traceback (most recent call last): File "", line 1, in import cv2 ImportError: Module use of python27.dll conflicts with this version of Python.

I have noticed that python 2.7 is used to install opencv. Is it a must o use 2.7 version?
Also as I know tensorflow will not support if I use another version of python(other than 3.5)

Giordano
  • 4,768
  • 3
  • 24
  • 47
George
  • 15
  • 2
  • 7

5 Answers5

2

You can try using

python -m pip install opencv-python

This method uses the unofficial OpenCV PyPi wheels for Linux, Mac and Windows

sankalp
  • 31
  • 2
1

Did you download open cv for Python 3? Try this:

  1. Make sure you have numpy installed
  2. Download open cv for Python 3 from here: http://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv (not sure if this will work with Python 3.5, should work with 3.2)
  3. Run pip install opencv_python-your_verison_here.whl
Artur
  • 733
  • 10
  • 25
  • 1
    Where should I copy this download file? – George Jul 04 '17 at 07:11
  • I think that you should run pip in the directory where the whl file is located. If you downloaded .whl to c:\Users\George\Downloads, just open cmd, enter `cd c:\Users\George\Downloads` and than `pip your_commands`. Also, take a look here: https://stackoverflow.com/questions/27885397/how-do-i-install-a-python-package-with-a-whl-file – Artur Jul 04 '17 at 07:14
  • Does these binaries really work. I mean opencv is a big library and can't be packaged into a single wheel – Arpit Solanki Jul 04 '17 at 10:01
  • @Arthur, Thanks for the answer but didn't work. Still get the incompatible problem – George Jul 04 '17 at 10:20
  • Sorry to hear that. I can't help you more remotely. Maybe try to follow some tutorial? You could also uninstall/unregister Python 3 and install Python 2.7 only and than download and install OpenCV for Py2. – Artur Jul 04 '17 at 10:22
  • @Artur, well Tensorflow doesnt work for the python 2.7. That is a problem too. Do you know whether Scikit work in python 3.5? I could see it support upto 3.4 – George Jul 04 '17 at 10:46
  • I guess it should work but I can't confirm, I haven't updated to 3.5 yet. – Artur Jul 04 '17 at 18:13
1

Since PyCharm is tagged I'm assuming you are wanting to know how to get opencv installed in PyCharm specifically. There is a PyCharm guide for installing packages here.

Step by step would be...

  1. File | Settings | Project:MyProject | Project Interpreter
  2. Click the + symbol on the right
  3. Type opencv-python
  4. Select opencv-python
  5. Click Install Package at the bottom left

Opencv should now be added to PyCharm. You can verify that it is by...

  1. Tools | Python Console...
  2. Clicking in the console window which pops up on the bottom
  3. import cv2
nanotek
  • 1,589
  • 8
  • 21
  • I tried this solution. But when I import the package it gives me an error. > Traceback (most recent call last): File "", line 1, in File "C:\Program Files\JetBrains\PyCharm 2017.1.4\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import module = self._system_import(name, *args, **kwargs) ImportError: DLL load failed: %1 is not a valid Win32 application. – George Jul 05 '17 at 03:39
  • Found a [useful link](https://stackoverflow.com/questions/33200025/cant-import-cv2-dll-load-failed). They are saying you need to download the visual c++ redistribution package which I guess [is here](https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads) – nanotek Jul 05 '17 at 13:44
  • I will try this. Thanks a lot for this answer – George Jul 05 '17 at 17:41
0

There are a lot of suggestions on how to solve this, but this was actually very easy to solve when using Anaconda. The problem is not the Visual C++ 2015 redistribution, but rather the python3.dll which is missing from C:\Users\username\AppData\Local\Continuum\Anaconda3 as your second link suggests.

A lot of these sites suggests downloading it manually, but according to this thread ContinuumIO/anaconda-issues#1394 the most recent anaconda packages should all include the missing python3.dll file. So by updating python with conda, this was solved:

**conda update python**
-1

try typing this into your terminal :

pip install opencv_python.

This worked for me.I have Python 3.5.2.

akash rao
  • 21
  • 1
  • 3