Skip to content
Advertisement

How to tell pip that a package(opencv) has been compiled from source

Because of some specific requirements I needed to compile a package (opencv with cuda support) from source.

After successfull compilation my python-environment is able to import opencv without a problem:

JavaScript

But if I try pip list opencv-python is not part of it:

JavaScript

The problem is that afterwards I need to install more packages via pip install -r requirements.txt and some of the packages listed in requirements.txt have opencv as a dependency. As pip is not aware of the opencv installation it now installes a different opencv version. Having two different versions installed along side each other does not sound like a clever solution for me… I could uninstall the pip install opencv later but that does not seem to be a good solution either…

So how can I make pip aware of the other opencv installation before running the pip install?

Advertisement

Answer

After you compile opencv, you can install the package with pip or python setup.py install. I would recommend building a Python wheel for opencv+cuda, and then installing that wheel. Having a wheel will make installing easier if you ever need to reinstall or make a new environment.

The general steps are:

  1. Compile opencv
  2. Change into the opencv python directory (with setup.py) and run python setup.py bdist_wheel
  3. Run auditwheel repair my-python-wheel-1.5.2-cp35-cp35m-linux_x86_64.whl (change the wheel filename) (from https://stackoverflow.com/a/42106034/5666087)

You can get auditwheel with pip install auditwheel.

Another useful reference is the build documentation for the opencv-python wheels, available at https://github.com/skvark/opencv-python#build-process. You can modify those steps to your build.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement