# Problem with importing cv in python IDLE

**URL:** <https://forum.opencv.org/t/problem-with-importing-cv-in-python-idle/9023>\
**Category:** Python\
**Created:** [June 3, 2022, 8:18am UTC](https://forum.opencv.org/t/problem-with-importing-cv-in-python-idle/9023 "2022-06-03T08:18:23Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kintaro](https://avatars.discourse-cdn.com/v4/letter/k/e56c9b/32.png) [@Kintaro](https://forum.opencv.org/u/Kintaro)\
**Post date:** [June 3, 2022, 8:18am UTC](https://forum.opencv.org/t/problem-with-importing-cv-in-python-idle/9023/1 "2022-06-03T08:18:24Z")

</div>

Hello,

Im a complete newbie in OpenCV and have a very basic question.

I followed the tutorial from

[https://docs.opencv.org/4.x/d5/de5/tutorial\_py\_setup\_in\_windows.html](https://docs.opencv.org/4.x/d5/de5/tutorial_py_setup_in_windows.html)

for getting OpenCV run with python and im already stuck at  
"  
5. Goto **opencv/build/python/2.7** folder.  
6. Copy **cv2.pyd** to **C:/Python27/lib/site-packages**.  
"

above in the tutorial it is said, that newer versions of Python should work fine, so I have 3.10 installed.

Now when I follow these steps and copy cv2.pyd to C:/Python310/lib/site-packages and try to import it in IDLE it gives me following error

```auto
Traceback (most recent call last):
  File "<pyshell#7>", line 1, in <module>
    import cv2 as cv
ImportError: DLL load failed while importing cv2: Das angegebene Modul wurde nicht gefunden.

```

Last line in german says “the declared module was not found”.

Obviously I can imagine, that a file made for python 2.7 like in the opencv/build/… directory won’t work with python 3.10. But I don’t see any alternative, considering there is no cv2.pyd file for Python 3.10 in the openCV directories.

I hope the solution is as obvious as I suppose. Any help is appreciated.

Kind regards,  
Kintaro

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [June 3, 2022, 8:34am UTC](https://forum.opencv.org/t/problem-with-importing-cv-in-python-idle/9023/2 "2022-06-03T08:34:45Z")

</div>

don’t do any of that. best remove that cv2.pyd from site-packages before proceeding.

instead, just **`pip3 install opencv-contrib-python`** and you’ll get everything installed.

what you tried to do would have required changes to the PATH environment variable. that cv2.pyd would have been for python3, if you downloaded a current binary build.

---

<div class="post-metadata">

**Author:** ![Kintaro](https://avatars.discourse-cdn.com/v4/letter/k/e56c9b/32.png) [@Kintaro](https://forum.opencv.org/u/Kintaro)\
**Post date:** [June 3, 2022, 8:10pm UTC](https://forum.opencv.org/t/problem-with-importing-cv-in-python-idle/9023/3 "2022-06-03T20:10:17Z")

</div>

Unfortunately it still doesnt work.

I still get the error message

```auto
import cv
Traceback (most recent call last):
  File "<pyshell#7>", line 1, in <module>
    import cv
ModuleNotFoundError: No module named 'cv'
import cv2
Traceback (most recent call last):
  File "<pyshell#8>", line 1, in <module>
    import cv2
ImportError: DLL load failed while importing cv2: Das angegebene Modul wurde nicht gefunden.

```

when I try to import with

```auto
import cv2

```

or

```auto
import cv

```

In my site-packages directory, I now have the folder opencv\_contrib\_python-4.5.5.64.dist-info

but none without the .dist-info as I have one of both with numpy for example.

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [June 4, 2022, 1:12am UTC](https://forum.opencv.org/t/problem-with-importing-cv-in-python-idle/9023/4 "2022-06-04T01:12:17Z")

</div>

ok so clean out _everything_ in site-packages that has “cv2” in the name.

“ImportError: DLL load failed” usually only happens when you install stuff manually. I’ve never had that happen with the package from PyPI (pip install …).

if that still doesn’t work, you should try rebooting the computer.

if that still doesn’t work, post your PATH variable

---

<div class="post-metadata">

**Author:** ![Kintaro](https://avatars.discourse-cdn.com/v4/letter/k/e56c9b/32.png) [@Kintaro](https://forum.opencv.org/u/Kintaro)\
**Post date:** [June 4, 2022, 9:24am UTC](https://forum.opencv.org/t/problem-with-importing-cv-in-python-idle/9023/5 "2022-06-04T09:24:31Z")

</div>

Thank you for your help.

It still didn’t work, though. I’ll post the path-variables tonight, when I am back from work.

---

<div class="post-metadata">

**Author:** ![Kintaro](https://avatars.discourse-cdn.com/v4/letter/k/e56c9b/32.png) [@Kintaro](https://forum.opencv.org/u/Kintaro)\
**Post date:** [June 4, 2022, 11:44pm UTC](https://forum.opencv.org/t/problem-with-importing-cv-in-python-idle/9023/6 "2022-06-04T23:44:52Z")

</div>

Im not quite sure which path-variable you mean exactly, but I figure the only ones making sense in this context are the ones of python.

So in my user-variables I have under path:

C:\Users\User\AppData\Local\Programs\Python\Python310  
C:\Users\K\AppData\Local\Programs\Python\Python310\Scripts  
C:\Users\K\AppData\Local\Microsoft\WindowsApps  
C:\Users\K.dotnet\tools

and in my system-variables under path I have:

%SystemRoot%\system32  
C:\Program Files (x86)\Common Files\Oracle\Java\javapath  
%SystemRoot%  
%SystemRoot%\System32\Wbem  
%SYSTEMROOT%\System32\WindowsPowerShell\v1.0  
%SYSTEMROOT%\System32\OpenSSH\

Is it possible, that the whole problem has something to do with opencv being for 32 bit and python 3.10.4 is 64 bit so it has problems with compatibility?

Otherwise Im not sure which mistakes I could have done since I simply followed the steps in the tutorials.

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [June 5, 2022, 11:25am UTC](https://forum.opencv.org/t/problem-with-importing-cv-in-python-idle/9023/7 "2022-06-05T11:25:13Z")

</div>

> [@Kintaro](#):
>
> opencv being for 32 bit

no, OpenCV is 64-bit.

that tutorial is outdated.

if you just want OpenCV in python, there’s nothing to build and nothing to “download”. just `pip install opencv-contrib-python` and make sure to install just _one_ of the packages. opencv-contrib-python conflicts with opencv-python. they both contain the base modules.

that “pyshell” (IDLE?) stuff makes me wonder… try without IDLE, do this:

- type Win+R
- enter `python`
- click OK

![image](https://us1.discourse-cdn.com/flex020/uploads/opencv/original/2X/b/b9c28bf2b83e094a80a42bf4bba807e68baadf44.png)

then type `import cv2` into the terminal and see what that does. does that also complain about not finding DLLs, like IDLE does?

---

<div class="post-metadata">

**Author:** ![Kintaro](https://avatars.discourse-cdn.com/v4/letter/k/e56c9b/32.png) [@Kintaro](https://forum.opencv.org/u/Kintaro)\
**Post date:** [June 5, 2022, 1:54pm UTC](https://forum.opencv.org/t/problem-with-importing-cv-in-python-idle/9023/8 "2022-06-05T13:54:02Z")

</div>

I tried that before and it gave me the same error.

I figured that I probably made some non-obvious rookie mistake when setting up python (even though I can not imagine what that might have been, since I didn’t do anything special like changing directories or such) and just uninstalled python 3.10.x and installed the stable version 3.9.13, even though Im not 100 % sure what stable means and if that has any benefits in my regards.

Nevertheless, after that I again installed opencv using your recommended command and it worked. Now I can import opencv and access its methods in the IDLE, as well as in other IDE’s.

Sorry if I wasted your time, but in the end your help was the key to getting it run and beyond that I learned a thing or two. So, again, thank you very much. Great to have guys like you, to help out guys like me :).

---

<div class="post-metadata">

**Author:** ![Kintaro](https://avatars.discourse-cdn.com/v4/letter/k/e56c9b/32.png) [@Kintaro](https://forum.opencv.org/u/Kintaro)\
**Post date:** [June 5, 2022, 1:57pm UTC](https://forum.opencv.org/t/problem-with-importing-cv-in-python-idle/9023/9 "2022-06-05T13:57:26Z")

</div>

PS: If you have any tips, where I could find a (free) consistent opencv/python-tutorial, that’d be great. I mean there are lots on youtube of course, but maybe there is one you could recommend.
