Build and install the Python 3 module

asked 2020-05-18 19:27:11 -0500

rgov gravatar image

updated 2020-05-18 19:27:35 -0500

I built OpenCV 4.x from a git checkout with the necessary options to build the Python 3 module. The configuration output includes:

--   OpenCV modules:
--     To be built:                 ... python2 python3 ...

--   Python 3:
--     Interpreter:                 /blah/.venv/bin/python3 (ver 3.6.5)
--     Libraries:                   /blah/python-3.6.5/lib/libpython3.6m.so (ver 3.6.5)
--     numpy:                       /blah/.venv/lib/python3.6/site-packages/numpy/core/include (ver 1.17.0)
--     install path:                /blah/.venv/lib/python3.6/site-packages

So it looks good. When I compile, it creates the file lib/python3/cv2.cpython-36m-x86_64-linux-gnu.so inside the build directory.

However, I can't figure out how I'm supposed to install this. I've tried cmake --build . --target install. This does not even install the Python 3 .so file to the install prefix, it only copies lib/python2.7/site-packages/cv2.so.

Can I create an egg or something installable from my build?

edit retag flag offensive close merge delete

Comments

R u using Raspberry Pi?

supra56 gravatar imagesupra56 ( 2020-05-18 21:08:10 -0500 )edit

This looks good. Can you post the output of sudo make install | grep pyth?

kbarni gravatar imagekbarni ( 2020-05-19 04:23:01 -0500 )edit

Take look;

Python 2:
    Interpreter:                 /usr/bin/python2.7 (ver 2.7.16)
    Libraries:                   /usr/lib/arm-linux-gnueabihf/libpython2.7.so (ver 2.7.16)
    numpy:                       /usr/lib/python2.7/dist-packages/numpy/core/include (ver 1.16.2)
    install path:                lib/python2.7/dist-packages/cv2/python-2.7

  Python 3:
    Interpreter:                 /usr/bin/python3 (ver 3.7.3)
    Libraries:                   /usr/lib/arm-linux-gnueabihf/libpython3.7m.so (ver 3.7.3)
    numpy:                       /usr/lib/python3/dist-packages/numpy/core/include (ver 1.16.2)
    install path:                lib/python3.7/dist-packages/cv2/python-3.7

  Python (for build):            /usr/bin/python3
supra56 gravatar imagesupra56 ( 2020-05-19 08:37:29 -0500 )edit

OpenCV 4.x must including python 2. You don't need install by urself. OpenCV 4.x will take a care for u,.

supra56 gravatar imagesupra56 ( 2020-05-19 08:39:12 -0500 )edit