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

OpenCV custom Linux built whl doesn't include Qt libraries #1020

Open
ioctl-user opened this issue Aug 22, 2024 · 9 comments
Open

OpenCV custom Linux built whl doesn't include Qt libraries #1020

ioctl-user opened this issue Aug 22, 2024 · 9 comments

Comments

@ioctl-user
Copy link

ioctl-user commented Aug 22, 2024

I'm building OpenCV with Qt support for Linux. Resulting whl file doesn't include Qt libraries as expected (whl from the pypi.org has no such problem, all libs (Qt and others) are included there).

Steps to reproduce.

Run Ubuntu in docker container:

docker run -it --rm -v /tmp/out:/out ubuntu:20.04

Run inside docker container:

# Prepare system
apt update && apt upgrade -y
DEBIAN_FRONTEND=noninteractive apt install -y python3-pip build-essential patchelf libgl1-mesa-glx libglib2.0-0 python3 python3-dev qt5-default git unzip

# Build and install opencv-python
git clone --recursive https://github.com/opencv/opencv-python.git

cd opencv-python/

export CMAKE_BUILD_PARALLEL_LEVEL=8
export CMAKE_ARGS="-DWITH_QT=ON"

pip wheel . --verbose

# Unpack and check resulting file:
mkdir test
cd test
cp ../opencv_python*whl out.zip
unzip out.zip

find . | grep -i qt # No Qt library is included
ldd cv2/cv2.abi3.so  | grep -i qt # cv2 so has Qt dependency

How can I build package with all libraries included?

@skvark
Copy link
Member

skvark commented Aug 23, 2024

Check out https://github.com/pypa/auditwheel and step 6. in the manual build guide in the README: https://github.com/opencv/opencv-python?tab=readme-ov-file#manual-builds

@ioctl-user
Copy link
Author

ioctl-user commented Aug 24, 2024

Check out https://github.com/pypa/auditwheel and step 6. in the manual build guide in the README: https://github.com/opencv/opencv-python?tab=readme-ov-file#manual-builds

Thanks, much better!

However, built package still incomplete - there is no libqxcb.so library from the Qt (which is present in official build), so Linux Qt GUI not working.

How to fix this?

My build command sequence to run inside manylinux2014 docker:

cd
git clone --recursive https://github.com/opencv/opencv-python.git
cd opencv-python/

export CMAKE_BUILD_PARALLEL_LEVEL=8
export CMAKE_ARGS="-DWITH_QT=ON -DWITH_IPP=OFF -DWITH_PNG=OFF WITH_WEBP=OFF -DWITH_TIFF=OFF -DWITH_JASPER=OFF -DWITH_OPENJPEG=OFF -DWITH_OPENEXR=OFF -DWITH_IMGCODEC_HDR=OFF -DWITH_IMGCODEC_SUNRASTER=OFF -DWITH_IMGCODEC_PXM=OFF -DWITH_IMGCODEC_PFM=OFF -DWITH_FFMPEG=OFF"
time python3.9 -m pip wheel . --verbose
auditwheel repair opencv_python*whl

@skvark
Copy link
Member

skvark commented Aug 25, 2024

You need to patch the auditwheel lib whitelist before running it: https://github.com/opencv/opencv-python/blob/4.x/patch_auditwheel_whitelist.py

@ioctl-user
Copy link
Author

You need to patch the auditwheel lib whitelist before running it: https://github.com/opencv/opencv-python/blob/4.x/patch_auditwheel_whitelist.py

I have tried, but it's not working:

$ python3.9 ./patch_auditwheel_whitelist.py 
Traceback (most recent call last):
  File "/home/ci/opencv-python/./patch_auditwheel_whitelist.py", line 4, in <module>
    from auditwheel import policy
ModuleNotFoundError: No module named 'auditwheel'

I have installed another one, patch and run with the following commands:

python3.9 -m pip install auditwheel
python3.9 ./patch_auditwheel_whitelist.py
python3.9 -m auditwheel repair opencv_python*whl

But seems nothing changed - there is no libqxcb.so in resulting whl-package.

Did I missed something else?

@skvark
Copy link
Member

skvark commented Aug 27, 2024

Ah.. the library that is missing requires also CMakelists patch: https://github.com/opencv/opencv-python/blob/4.x/patches/patchQtPlugins which is applied only if CI_BUILD env var is set to true:

if is_CI_build:

@skvark
Copy link
Member

skvark commented Aug 27, 2024

You are trying to emulate the CI build environment so the steps need to follow the same steps as in this repo's CI process.

@ioctl-user
Copy link
Author

You are trying to emulate the CI build environment so the steps need to follow the same steps as in this repo's CI process.

Thanks for advice! Unfortunately I cannot understand and parse all build files so well.
For now trying to build it on Github with action with modifications. Hope, this will works.

If this patch is required, why it's applied only in CI_BUILD case?

@skvark
Copy link
Member

skvark commented Aug 28, 2024

You are trying to emulate the CI build environment so the steps need to follow the same steps as in this repo's CI process.

Thanks for advice! Unfortunately I cannot understand and parse all build files so well. For now trying to build it on Github with action with modifications. Hope, this will works.

If this patch is required, why it's applied only in CI_BUILD case?

It's required only when building PyPI-compatible wheels for redistribution for maximum portability. When you make a wheel locally and use the wheel on the same machine in the same environment, there's no need to bundle everything in the wheel since the libraries are already available in your system.

@ioctl-user
Copy link
Author

You are trying to emulate the CI build environment so the steps need to follow the same steps as in this repo's CI process.

Thanks for advice! Unfortunately I cannot understand and parse all build files so well. For now trying to build it on Github with action with modifications. Hope, this will works.
If this patch is required, why it's applied only in CI_BUILD case?

It's required only when building PyPI-compatible wheels for redistribution for maximum portability. When you make a wheel locally and use the wheel on the same machine in the same environment, there's no need to bundle everything in the wheel since the libraries are already available in your system.

For local need opencv with python bindings can be built and installed directly without opencv-python.
If so, non CI_BUILD mode in opencv-python is useless.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants