You are not logged in.

#1 2023-04-13 15:16:34

tony5429
Member
Registered: 2006-03-28
Posts: 1,017

[SOLVED] Python-opencv Doesn't Install opencv-python

I have a python script I'd like all users on my machine to be able to run. That python script requires the python library "opencv-python" which each user can individually install using "pip install opencv-python", after which point they can use the subject script. However, it would be nice if the opencv-python python package could be installed once at the system level instead. I've read that running "pip install" commands as root is not recommended. I found the arch package python-opencv, which is in the Extra repo, but installing it doesn't seem to actually provide the opencv-python library... Does anyone know what I'm missing / how to do this?

Last edited by tony5429 (2023-04-13 22:13:40)

Offline

#2 2023-04-13 15:56:27

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 22,947

Re: [SOLVED] Python-opencv Doesn't Install opencv-python

It does install it, what exactly makes you think it doesn't? The import/lib to include will be cv2 but that's even documented on the pip FAQ.

Last edited by V1del (2023-04-13 15:58:41)

Offline

#3 2023-04-13 16:31:39

tony5429
Member
Registered: 2006-03-28
Posts: 1,017

Re: [SOLVED] Python-opencv Doesn't Install opencv-python

The first line of the Python script is "import cv2". It doesn't work if I just have python-opencv installed, but if I run "pip install opencv-python" first, it then does work...

Offline

#4 2023-04-13 16:39:57

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 22,947

Re: [SOLVED] Python-opencv Doesn't Install opencv-python

it should, what error message do you get?

Offline

#5 2023-04-13 17:29:21

tony5429
Member
Registered: 2006-03-28
Posts: 1,017

Re: [SOLVED] Python-opencv Doesn't Install opencv-python

I'll try it again and post here, when I'm back at my machine. In the meantime, are you saying installing the python-opencv package should...

1. Instantly allow a python script that imports cv2 to work,

or

2. Provide the system the ability for its users to install opencv-python via "pip install opencv-python" (presumably by providing the library locally on the system so pip doesn't have to download it from the internet), after which point a python script that imports cv2 will work?

Offline

#6 2023-04-13 17:33:57

Scimmia
Fellow
Registered: 2012-09-01
Posts: 11,997

Re: [SOLVED] Python-opencv Doesn't Install opencv-python

option 1.

What does `type -a python` give you? `pacman -Q python python-opencv`?

option 2 is not a thing at all.

Last edited by Scimmia (2023-04-13 17:39:17)

Offline

#7 2023-04-13 21:44:35

tony5429
Member
Registered: 2006-03-28
Posts: 1,017

Re: [SOLVED] Python-opencv Doesn't Install opencv-python

With python-opencv installed, the "import cv2" command fails:

[tony@mylinux ~]$ pacman -Q python-opencv
python-opencv 4.7.0-7
[tony@mylinux ~]$ python -c 'import cv2'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: libhdf5.so.310: cannot open shared object file: No such file or directory
[tony@mylinux ~]$ type -a python
python is /usr/bin/python
python is /bin/python

Last edited by tony5429 (2023-04-13 21:44:48)

Offline

#8 2023-04-13 21:49:46

Scimmia
Fellow
Registered: 2012-09-01
Posts: 11,997

Re: [SOLVED] Python-opencv Doesn't Install opencv-python

So this is a simple partial update problem, your hdf5 package is out of date. FULLY update your system, always. Never run pacman -Sy unless someone who really understands the system tells you to. Don't replace system library packages with other versions unless you're going to stay on top of them.

I think that covers the most common causes.

Last edited by Scimmia (2023-04-13 21:54:50)

Offline

#9 2023-04-13 22:13:15

tony5429
Member
Registered: 2006-03-28
Posts: 1,017

Re: [SOLVED] Python-opencv Doesn't Install opencv-python

Ah! Yes, you were right. I had installed python-opencv without first updating the whole system. Just did a full system upgrade and that fixed it right away. Thanks!

Offline

Board footer

Powered by FluxBB