0

I am currently new to python. I have installing python 3.6 using Anaconda version 4.5. After installing few packages below I am unable to import cv2:

pip install numpy scipy matplotlib scikit-learn jupyter
pip install opencv-contrib-python

Error Unable to import CV2

I have tried installing various version of cv2 but none works.

Kapil Bhatt
  • 121
  • 2
  • 10
  • try: `python -m pip install XXX`; or `use conda and switch env` – Kinght 金 Oct 13 '18 at 10:33
  • Tried the same it doesn't work. I think the problem is in init file line 2 where its written "from .cv2 import * " but in my cv2 folder there is no directory name cv2. – Kapil Bhatt Oct 13 '18 at 10:49
  • There shoud be a file named: `lib\\site-packages\\cv2\\cv2.cp36-win_amd64.pyd` on windows or `site-packages/cv2.cpython-36m-x86_64-linux-gnu.so` on Linux if has been installed successfully. – Kinght 金 Oct 13 '18 at 10:57
  • Yes, this file is present with name cv2.cp36-win_amd64.pyd. The problem is in the import only, rest the package and conda is working fine. – Kapil Bhatt Oct 13 '18 at 11:14

2 Answers2

2

First of all, when only conda and python are installed, activate the conda environment then use following command to install

conda install -c anaconda opencv 

OR

conda install -c conda-forge opencv

if you have R and Rstudio or multiple environments, there are chances of conflict of different versions of python.

Then you first have to activate the conda environment and run the following command:

pip install opencv-python

that will take few minutes to install the opencv library.

S Habeeb Ullah
  • 968
  • 10
  • 15
1

First, try again using the conda command:

conda install -c conda-forge opencv

A common mistake I personally did that caused this kind of problem is when you install the package in an environment but run jupyter from another one (like from the base environment).

I would suggest you:

1- use conda list in your environment to check the packages are correctly installed.

2- make sure the environment where you installed the packages is activate before running the command: jupyter notebook

Wazaki
  • 899
  • 1
  • 8
  • 22
  • Thanks for your inputs. I tried the same but the problem still persists. I think the problem is in __init__ file line 2 where its written "from .cv2 import * " but in my cv2 folder there is no directory name cv2. – Kapil Bhatt Oct 13 '18 at 10:48
  • check out the solutions stated here then: [link](https://stackoverflow.com/questions/43184887/dll-load-failed-error-when-importing-cv2) – Wazaki Oct 13 '18 at 11:02