ModuleNotFoundError: No module named 'cv2'
I just installed Anaconda, downloaded the repo, and activated conda, all per docs/the readme. I'm getting this:
(ldm)...$ python scripts/txt2img.py --prompt "a photograph of an astronaut riding a horse" --plms
Traceback (most recent call last):
File "/home/c/.code/lab/stable-diffusion/scripts/txt2img.py", line 2, in <module>
import cv2
ModuleNotFoundError: No module named 'cv2'
Which seems to stem from line 15 in environment.yaml (I guess opencv is cv2):
- opencv-python==4.1.2.30
When I run conda search opencv-python, I'm getting this:
$ conda search opencv-python
Loading channels: done
No match found for: opencv-python. Search: *opencv-python*
PackagesNotFoundError: The following packages are not available from current channels:
- opencv-python
Current channels:
- https://repo.anaconda.com/pkgs/main/linux-64
- https://repo.anaconda.com/pkgs/main/noarch
- https://repo.anaconda.com/pkgs/r/linux-64
- https://repo.anaconda.com/pkgs/r/noarch
To search for alternate channels that may provide the conda package you're
looking for, navigate to
https://anaconda.org
and use the search bar at the top of the page.
conda list returns a list that seems to have what I need:
opencv-python 4.1.2.30 pypi_0 pypi
opencv-python-headless 4.6.0.66 pypi_0 pypi
opencv-python's latest version is 4.6.0.66 as of 8 June 2022.
Solution: I'm on Kubuntu with Python3.9. Make sure pip is installed (new install for me) Make sure distutils are installed and on the latest (apt install python3.9-distutils) Use pip to install opencv-python (python -m pip install opencv-python)
It seemed to fix my problem. It seems like to use conda to install opencv-python you have to use an unofficial channel which I'm not stoked about, but using pip is another option. Just for detail, here's why I updated distutils.
Now to figure out where torch is at! Happy diffusing.
Hey there! I had the same issue and really struggled to understand where I went wrong. Turns out, not all terminals are equal, and on Windows 11, PowerShell does not seem to function very well with Conda. Using CMD I was able to get past this issue immediately. Hope this helps anyone else facing this issue!