with python2.7 and 3.4

asked 2015-12-15 10:47:37 -0500

Terry gravatar image

updated 2015-12-16 08:10:59 -0500

boaz001 gravatar image

Hi, I built for python2.7 and python3.4 in raspbian. They both work and I can do import cv2.

However, when I wanted to understand where all the binaries are installed by cmake, I noticed something strange and I didn't understand.

Both py2.7 and py3.4 files are depending on the same shared objects. The following is the ldd output

    $ldd  #python 2.7 (0x7ee2d000)
    /usr/lib/arm-linux-gnueabihf/ (0x76e66000)
    ** => /usr/lib/arm-linux-gnueabihf/ (0x76b2f000)        ** => /lib/ (0x7691c000) => /lib/ (0x768c9000) => /lib/ (0x765f8000) => /lib/ (0x76561000)

    $ldd #python 3.4     (0x7ef97000)
    /usr/lib/arm-linux-gnueabihf/ (0x76dce000)
    ** => /usr/lib/arm-linux-gnueabihf/ (0x769fe000)        ** => /lib/ (0x767eb000) => /lib/ (0x76798000) => /lib/ (0x764c7000) => /lib/ (0x76430000)

Do note the offsets in brackets seem to differ between the two versions. Otherwise both py2.7 and py34 are dependent on the shared objects ( etc).

Is this correct or is something wrong and it may cause problems later. If this right, could you please tell me how this works and why mixing so files is ok here?
Thanks T

edit retag flag offensive close merge delete


"Is this correct or is something wrong" - nothing wrong, this is correct. only the python wrapper differs, the underlying opencv c++ code is the same.

btw, the recommended way is to build statically (cmake -DBUILD_SHARED_LIBS=OFF) , so it no more depends on so's at runtime

berak gravatar imageberak ( 2015-12-17 03:05:15 -0500 )edit

Hey, is this -DBUILD_SHARED_LIBS=OFF the right way? Oh god. That would have saved so much time. It really ought to be mentioned in the website somewhere.

Terry gravatar imageTerry ( 2015-12-17 23:44:19 -0500 )edit

it's mentioned here and here , unfortunately only in java context.

as a sidenote, you'll still need the opencv_ffmpeg so around, if you want read from ipcams or such.

berak gravatar imageberak ( 2015-12-18 00:01:24 -0500 )edit

Hi, What about CMAKE_INSTALL_PREFIX? Everyone is setting it to /usr/local. Can I set it to my home directory ~/usr/local? Infact I thought the good practice was to install everything in your python virtual environment like ~/py27env , ~/py3env ?

Terry gravatar imageTerry ( 2015-12-19 02:10:25 -0500 )edit

sure, correct idea.

berak gravatar imageberak ( 2015-12-19 02:37:10 -0500 )edit

Thanks. Will do so in the future. Mean time I went ahead with /usr/local as install prefix.

I discovered somethings strange. I built opencv under python2.7 virtual env. (Basically virtualenv -p /usr/bin/python2.7 )

I did an out of source build under the directory buildpy27. This built two files under the build tree : buildpy27/lib/ AND buildpy27/lib/python3/ # why the later one??

Any ideas why both .so files are getting built. Does that mean I don't need a seperate opencv build for the python3.4?.

And doing sudo make install created these : /usr/local/lib/python2.7/site-packages/ AND /usr/local/lib/python3.4/site-packages/ So, why this Wouldn't this be built and installed only when I build under python3 env?

Terry gravatar imageTerry ( 2015-12-19 06:19:16 -0500 )edit