5

After installing miniconda with python 3.7 I do the following:

conda create --name opencv_test python=3.7
conda activate opencv_test
conda install -c anaconda opencv

Then to test the environement I do:

python
>>> import cv2
>>> exit()

Everything goes according to plan

Then if I launch PyCharm or vs code, set my new environment as the interpreter and create a simple file that contains only

import cv2

On launch I get:

ImportError: DLL load failed: The specified module could not be found.

What I learned from the internets:

This, this and this, all those posts refer to a problem that seems similar, the difference being that the issue for me only happens when using IDEs

What I tried before posting here:

  1. Recreating the environment multiple times switching channels.
  2. As it seemed to be a path issue, I added the paths which contained opencv dll to the environment paths in PyCharm settings one at a time

What I just tried after spending a considerable amount of time creating this post:

conda update conda 

This weirdly downgrades python to 3.6

conda create --name opencv_test_2 python=3.6
conda activate opencv_test_2
conda install -c anaconda opencv

This seems to fix all the issues but:

  • I don't know what just happened and why the issue only appeared on IDEs
  • I'd like to use python 3.7

So in short, why when using python 3.7 and PyCharm I seem to be unable to import opencv even if it works on command line?

Thanks in advance.

Moshe Slavin
  • 5,127
  • 5
  • 23
  • 38
Treizh
  • 322
  • 5
  • 12
  • 4
    Try to activate the env from terminal, then start your pycharm.exe in the same terminal. Or you can set python project environment (opencv_test/xxx/bin/python.exe )in you pycharm. – Kinght 金 Oct 02 '18 at 11:43
  • @knight, sorry for the delay. Thank you it's a workaround but launching the program from an activated environment seems to work (not activating it in the options). I still don't understand the issue and how it will affect if I send my code/environement to people – Treizh Jun 26 '19 at 10:14

0 Answers0