pythonopencvubuntudiplib

Compiling Python Module for Specific Version of Python


RI am having to manually compile a library/module for Python on Ubuntu 16.04 and am running into problems. The library is here:

DIPlib 3 - PyDIP

It's a size quantifier for OpenCV. The problem is when running the command:

cmake /home/cooper/diplib-master/ -DCMAKE_INSTALL_PREFIX=$HOME/dip -DPYDIP_INSTALL_PATH=$(python3 -m site --user-site)

as described in the instructions, it builds the file in the path /home/cooper/.local/lib/python3.5/site-packages/PyDIP/PyDIP_bin.so. When I go to run my code using python3 my_program.py, I get the error:

undefined symbol: _Py_ZeroStruct.

I tried compiling it with the default path (python 2.7 for my system) and the Zero Struct error dissapears, but since the code was written for Python 3 it doesnt work as intended (get import errors for importlib). So my question is how do I point Python or Ubuntu to the .local file path so it knows where to find the compiled code? Or, if I went about it all wrong, how do I properly compile this code to work on my system? I've been reading about environment variables and system paths, but i dont think I understand it well enough to not end up just wreaking havoc on my computer.


Solution

  • The PyDIP CMake script should prefer Python 3 over Python 2 when building, you could try pulling the latest master to see if that gives you better luck.

    If this doesn’t work, you can add

    -DPYBIND11_PYTHON_VERSION=3.5
    

    to the CMake command to specify which version of Python to target.