Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error importing cv2 on Windows 10 #19

Closed
tonnydourado opened this issue Jan 25, 2023 · 7 comments
Closed

Error importing cv2 on Windows 10 #19

tonnydourado opened this issue Jan 25, 2023 · 7 comments
Labels
bug Something isn't working

Comments

@tonnydourado
Copy link

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
@initialcommit-io
Copy link
Contributor

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.

@tonnydourado
Copy link
Author

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.

@initialcommit-io
Copy link
Contributor

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

@tonnydourado
Copy link
Author

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'
>>>

@initialcommit-io
Copy link
Contributor

@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.

@initialcommit-io initialcommit-io added the bug Something isn't working label Feb 2, 2023
@initialcommit-io
Copy link
Contributor

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

@initialcommit-io
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants