[GH-ISSUE #19] Error importing cv2 on Windows 10 #15

Closed
opened 2026-03-02 16:47:07 +03:00 by kerem · 7 comments
Owner

Originally created by @tonnydourado on GitHub (Jan 25, 2023).
Original GitHub issue: https://github.com/initialcommit-com/git-sim/issues/19

I installed ffmpeg (manually) and manim, and they both work, but when I try to run git-sim merge develop, I get an error about importing cv2:

> git-sim merge develop
Manim Community v0.17.2

Traceback (most recent call last):
  File "c:\users\me\appdata\local\programs\python\python39\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "c:\users\me\appdata\local\programs\python\python39\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\me\Documents\workspace\my-project\venv\Scripts\git-sim.exe\__main__.py", line 4, in <module>
  File "C:\Users\me\Documents\workspace\my-project\venv\lib\site-packages\git_sim\__main__.py", line 6, in <module>
    import cv2
ModuleNotFoundError: No module named 'cv2'

Installing git-sim correctly installed opencv-python-headless, from what I see in the output of pip install git-sim:

pip install git-sim
(...)
Requirement already satisfied: opencv-python-headless in c:\users\me\documents\workspace\my-project\venv\lib\site-packages (from git-sim) (4.7.0.68)
(...)

As asked by the contributing guidelines:

  1. The steps you took that lead to the issue:
    • Installed ffmpeg manually
    • Installed manim with pip in a virtualenv
    • Installed git-sim with pip in a virtualenv
    • Ran git-sim merge develop
  2. Any error message(s) that you received: see above
  3. A description of any unexpected behavior: see above
  4. The version of Git-Sim you're running: 0.1.4
  5. The version of Python you're running and whether it's system-level or in a virtual environment: Python 3.9.6, in a virtualenv
  6. The operating system and version you're running: Windows 10 64 bits
Originally created by @tonnydourado on GitHub (Jan 25, 2023). Original GitHub issue: https://github.com/initialcommit-com/git-sim/issues/19 I installed `ffmpeg` (manually) and `manim`, and they both work, but when I try to run `git-sim merge develop`, I get an error about importing cv2: ``` > git-sim merge develop Manim Community v0.17.2 Traceback (most recent call last): File "c:\users\me\appdata\local\programs\python\python39\lib\runpy.py", line 197, in _run_module_as_main return _run_code(code, main_globals, None, File "c:\users\me\appdata\local\programs\python\python39\lib\runpy.py", line 87, in _run_code exec(code, run_globals) File "C:\Users\me\Documents\workspace\my-project\venv\Scripts\git-sim.exe\__main__.py", line 4, in <module> File "C:\Users\me\Documents\workspace\my-project\venv\lib\site-packages\git_sim\__main__.py", line 6, in <module> import cv2 ModuleNotFoundError: No module named 'cv2' ``` Installing `git-sim` correctly installed opencv-python-headless, from what I see in the output of pip install git-sim: ``` pip install git-sim (...) Requirement already satisfied: opencv-python-headless in c:\users\me\documents\workspace\my-project\venv\lib\site-packages (from git-sim) (4.7.0.68) (...) ``` As asked by the contributing guidelines: 1. The steps you took that lead to the issue: - Installed ffmpeg manually - Installed manim with pip in a virtualenv - Installed git-sim with pip in a virtualenv - Ran git-sim merge develop 2. Any error message(s) that you received: see above 3. A description of any unexpected behavior: see above 4. The version of Git-Sim you're running: 0.1.4 5. The version of Python you're running and whether it's system-level or in a virtual environment: Python 3.9.6, in a virtualenv 6. The operating system and version you're running: Windows 10 64 bits
kerem 2026-03-02 16:47:07 +03:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@initialcommit-io commented on GitHub (Jan 26, 2023):

Hi there @tonnydourado sorry for the delay. This may be a silly question, but is your virtual environment activated when you run your git-sim command?

Also what happens if you just run the Python interpreter and run import cv2? With and without your venv activated.

<!-- gh-comment-id:1405429924 --> @initialcommit-io commented on GitHub (Jan 26, 2023): Hi there @tonnydourado sorry for the delay. This may be a silly question, but is your virtual environment activated when you run your git-sim command? Also what happens if you just run the Python interpreter and run `import cv2`? With and without your venv activated.
Author
Owner

@tonnydourado commented on GitHub (Jan 26, 2023):

No worries, mate! Answering your questions: I'm pretty darn sure the virtualenv was activated, but I'll double check tomorrow at work. I'll also try to just import cv2 in the virtualenv. Without it, I'm sure it will give an impor error, because I install almost nothing on the global namespace.

For what is worth, I tried one of the manin getting started examples, the create circle one, and it worked. The default player didn't play the video, because it's a company machine and I do not think IT has installed any codecs, but ffplay played without issues.

<!-- gh-comment-id:1405602995 --> @tonnydourado commented on GitHub (Jan 26, 2023): No worries, mate! Answering your questions: I'm pretty darn sure the virtualenv was activated, but I'll double check tomorrow at work. I'll also try to just import cv2 in the virtualenv. Without it, I'm sure it will give an impor error, because I install almost nothing on the global namespace. For what is worth, I tried one of the manin getting started examples, the create circle one, and it worked. The default player didn't play the video, because it's a company machine and I do not think IT has installed any codecs, but ffplay played without issues.
Author
Owner

@initialcommit-io commented on GitHub (Jan 27, 2023):

@tonnydourado Hi again! Were you able to test this out?

<!-- gh-comment-id:1406246635 --> @initialcommit-io commented on GitHub (Jan 27, 2023): @tonnydourado Hi again! Were you able to test this out?
Author
Owner

@tonnydourado commented on GitHub (Feb 1, 2023):

So, I created a virtualenv from scratch, and this is what I'm getting with import cv2:

(git-sim-venv) > python
Python 3.9.6 (tags/v3.9.6:db3ff76, Jun 28 2021, 15:26:21) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\me\Documents\workspace\scratch\git-sim-venv\lib\site-packages\cv2\__init__.py", line 181, in <module>
    bootstrap()
  File "C:\Users\me\Documents\workspace\scratch\git-sim-venv\lib\site-packages\cv2\__init__.py", line 153, in bootstrap
    native_module = importlib.import_module("cv2")
  File "c:\users\me\appdata\local\programs\python\python39\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ImportError: DLL load failed while importing cv2: The specified module could not be found.

I think this is different than the stacktrace from when I opened the issue because before I tried to install open-cv manually. I get the same thing when running git-sim in this fresh venv, just with a couple of extra levels:

(git-sim-venv) > git-sim.exe merge develop
Traceback (most recent call last):
  File "c:\users\me\appdata\local\programs\python\python39\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "c:\users\me\appdata\local\programs\python\python39\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\me\Documents\workspace\scratch\git-sim-venv\Scripts\git-sim.exe\__main__.py", line 4, in <module>
  File "C:\Users\me\Documents\workspace\scratch\git-sim-venv\lib\site-packages\git_sim\__main__.py", line 6, in <module>
    import cv2
  File "C:\Users\me\Documents\workspace\scratch\git-sim-venv\lib\site-packages\cv2\__init__.py", line 181, in <module>
    bootstrap()
  File "C:\Users\me\Documents\workspace\scratch\git-sim-venv\lib\site-packages\cv2\__init__.py", line 153, in bootstrap
    native_module = importlib.import_module("cv2")
  File "c:\users\me\appdata\local\programs\python\python39\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ImportError: DLL load failed while importing cv2: The specified module could not be found.

import cv2 with no virtualenv just raises an import error, as expected:

> py
Python 3.9.6 (tags/v3.9.6:db3ff76, Jun 28 2021, 15:26:21) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'cv2'
>>>
<!-- gh-comment-id:1411568809 --> @tonnydourado commented on GitHub (Feb 1, 2023): So, I created a virtualenv from scratch, and this is what I'm getting with `import cv2`: ``` (git-sim-venv) > python Python 3.9.6 (tags/v3.9.6:db3ff76, Jun 28 2021, 15:26:21) [MSC v.1929 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import cv2 Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Users\me\Documents\workspace\scratch\git-sim-venv\lib\site-packages\cv2\__init__.py", line 181, in <module> bootstrap() File "C:\Users\me\Documents\workspace\scratch\git-sim-venv\lib\site-packages\cv2\__init__.py", line 153, in bootstrap native_module = importlib.import_module("cv2") File "c:\users\me\appdata\local\programs\python\python39\lib\importlib\__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) ImportError: DLL load failed while importing cv2: The specified module could not be found. ``` I think this is different than the stacktrace from when I opened the issue because before I tried to install open-cv manually. I get the same thing when running git-sim in this fresh venv, just with a couple of extra levels: ``` (git-sim-venv) > git-sim.exe merge develop Traceback (most recent call last): File "c:\users\me\appdata\local\programs\python\python39\lib\runpy.py", line 197, in _run_module_as_main return _run_code(code, main_globals, None, File "c:\users\me\appdata\local\programs\python\python39\lib\runpy.py", line 87, in _run_code exec(code, run_globals) File "C:\Users\me\Documents\workspace\scratch\git-sim-venv\Scripts\git-sim.exe\__main__.py", line 4, in <module> File "C:\Users\me\Documents\workspace\scratch\git-sim-venv\lib\site-packages\git_sim\__main__.py", line 6, in <module> import cv2 File "C:\Users\me\Documents\workspace\scratch\git-sim-venv\lib\site-packages\cv2\__init__.py", line 181, in <module> bootstrap() File "C:\Users\me\Documents\workspace\scratch\git-sim-venv\lib\site-packages\cv2\__init__.py", line 153, in bootstrap native_module = importlib.import_module("cv2") File "c:\users\me\appdata\local\programs\python\python39\lib\importlib\__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) ImportError: DLL load failed while importing cv2: The specified module could not be found. ``` `import cv2` with no virtualenv just raises an import error, as expected: ``` > py Python 3.9.6 (tags/v3.9.6:db3ff76, Jun 28 2021, 15:26:21) [MSC v.1929 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import cv2 Traceback (most recent call last): File "<stdin>", line 1, in <module> ModuleNotFoundError: No module named 'cv2' >>> ```
Author
Owner

@initialcommit-io commented on GitHub (Feb 1, 2023):

@tonnydourado I found the following post on StackOverflow:

https://stackoverflow.com/questions/52349669/dll-load-failed-when-import-cv2-opencv

It says the issue could be a combination of using Windows 10 N distribution with specific newer versions of OpenCV. It proposes 2 solutions:

  1. Install a Windows feature pack from https://support.microsoft.com/en-us/help/4562569/media-feature-pack-for-windows-10-n-may-2020

  2. Fall back to an earlier version of OpenCV, by uninstalling the existing one from your venv and then try this: pip install opencv-python-headless=3.3.0.9

It would be great if you could test out these options and let me know if one works for you.

<!-- gh-comment-id:1412918472 --> @initialcommit-io commented on GitHub (Feb 1, 2023): @tonnydourado I found the following post on StackOverflow: https://stackoverflow.com/questions/52349669/dll-load-failed-when-import-cv2-opencv It says the issue could be a combination of using Windows 10 N distribution with specific newer versions of OpenCV. It proposes 2 solutions: 1) Install a Windows feature pack from https://support.microsoft.com/en-us/help/4562569/media-feature-pack-for-windows-10-n-may-2020 2) Fall back to an earlier version of OpenCV, by uninstalling the existing one from your venv and then try this: `pip install opencv-python-headless=3.3.0.9` It would be great if you could test out these options and let me know if one works for you.
Author
Owner

@initialcommit-io commented on GitHub (Feb 5, 2023):

@tonnydourado Were you able to test out the suggestions above?

<!-- gh-comment-id:1418243353 --> @initialcommit-io commented on GitHub (Feb 5, 2023): @tonnydourado Were you able to test out the suggestions above?
Author
Owner

@initialcommit-io commented on GitHub (Feb 8, 2023):

Closing due to inactivity. Feel free to repoen with further details if the above solution didn't work.

<!-- gh-comment-id:1423071032 --> @initialcommit-io commented on GitHub (Feb 8, 2023): Closing due to inactivity. Feel free to repoen with further details if the above solution didn't work.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/git-sim#15
No description provided.