git-sim
git-sim copied to clipboard
Error importing cv2 on Windows 10
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:
- 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
- Any error message(s) that you received: see above
- A description of any unexpected behavior: see above
- The version of Git-Sim you're running: 0.1.4
- 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
- The operating system and version you're running: Windows 10 64 bits
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.
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.
@tonnydourado Hi again! Were you able to test this out?
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'
>>>
@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:
-
Install a Windows feature pack from https://support.microsoft.com/en-us/help/4562569/media-feature-pack-for-windows-10-n-may-2020
-
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.
@tonnydourado Were you able to test out the suggestions above?
Closing due to inactivity. Feel free to repoen with further details if the above solution didn't work.