4

Bit of a strange one here - I've installed opencv-python via pip install opencv-python, the installation was successful and can be seen via pip show opencv-python, but when trying to import it into a project the package can't be found. On further investigation there isn't actually an opencv (cv2?) folder in my site-packages, so I have no idea where it's retrieving the package info from. Has anyone ever come across this issue? I may be missing something totally obvious.

enter image description here

I've checked out a couple of similar questions but they seem to refer mainly to Linux; i.e. the package is in dist-packages rather than site-packages.

Links to questions:

Python-opencv import error, packages installed

Python package not found after installing package successfully

zbar missing from Python site-pakages after install

Edit - shifting some info from comments to question body:

pip install --force-reinstall --no-deps opencv-python reinstalls the package successfully

pip --version outputs the correct Python version and pip show -f opencv-python lists files correctly (even though they don't seem to exist when searched for in Windows explorer) - https://i.stack.imgur.com/B0psH.png

python -m site the sys.path directories are all correct - https://i.stack.imgur.com/zcGnR.png

toti08
  • 2,448
  • 5
  • 24
  • 36
RyanHx
  • 411
  • 3
  • 10
  • Try running `pip install --force-reinstall --no-deps opencv-python` – hoefling Jul 11 '19 at 17:50
  • @hoefling thanks for the response. Sadly no luck on that command - it successfully reinstalls the package but it's still missing from the directory and can't be imported via `import cv2` – RyanHx Jul 11 '19 at 18:02
  • Can you run 1. `pip --version` to check the python version listed (must be 3.7) and 2. run `pip show -f opencv-python` and check the list of installed files, what does it show? – hoefling Jul 11 '19 at 18:20
  • 1
    @hoefling Screenshot - https://i.imgur.com/6PQnOS9.png. The python version checks out, and apparently the cv2 folder exists, but is missing when searched for in Windows explorer and Python projects. Very strange. – RyanHx Jul 11 '19 at 18:38
  • So what is the output if you now run `python -c "import cv2"` or `py -3.7 -c "import cv2"`? – hoefling Jul 11 '19 at 18:42
  • @hoefling on both commands I'm receiving `ModuleNotFoundError: No module named 'cv2'` – RyanHx Jul 11 '19 at 18:46
  • Hmm, can you also add the output of `python -m site`? – hoefling Jul 11 '19 at 18:49
  • @hoefling https://i.imgur.com/xKpyUtk.png - USER_BASE & USER_SITE labelled as non-existent, would this be the source of the issue? – RyanHx Jul 11 '19 at 18:54
  • No, don't worry - what's important is that `lib\site-packages` is included in `sys.path`, the rest is not relevant here. Don't have any more ideas tbh as everything looks good from the python side. – hoefling Jul 11 '19 at 19:13
  • @hoefling no worries, I appreciate your time. – RyanHx Jul 11 '19 at 19:43
  • I have the same problem working on VDI in my company. Is there any decision so far? – Anton Makarov Oct 25 '22 at 07:28

1 Answers1

0

I had the same problem. So it's NOT Python's fault.

In my case i was working on VDI (some kind of virtual machine) and when i installed a library in venv, situated in "C:/Users/Anton/Projects/My_Project/venv" it happened to be created in some strange folder like "\some_symbols--08.bla.bla.bla\data...\anton\ files\My_Project\venv"

It is very similar to my folder, but not the same, like they where created together, but their love did not work well and they fell apart ))) SO the problem was in network or virtual machine bugs.

Anton Makarov
  • 562
  • 3
  • 12