clandmark icon indicating copy to clipboard operation
clandmark copied to clipboard

Python Binding Error ...

Open jiapei100 opened this issue 8 years ago • 22 comments

Hi,

Whenever I tried to enable BUILD_PYTHON_BINDINGS , I obtained the following error messages:

CMake Error at python_interface/CMakeLists.txt:4 (find_package): By not providing "Findclandmark.cmake" in CMAKE_MODULE_PATH this project has asked CMake to find a package configuration file provided by "clandmark", but CMake did not find one.

Could not find a package configuration file provided by "clandmark" with any of the following names:

 clandmarkConfig.cmake
 clandmark-config.cmake

Add the installation prefix of "clandmark" to CMAKE_PREFIX_PATH or set "clandmark_DIR" to a directory containing one of the above files. If "clandmark" provides a separate development package or SDK, be sure it has been installed.

Any suggestions please??? Can't current clandmark-git bind with python?

Cheers Pei

jiapei100 avatar Apr 12 '16 20:04 jiapei100

Hi @jiapei100,

what is your system, please? The Python interface build is so far tested only on linux, where it seem to work without problems. So any help here is highly appreciated.

uricamic avatar Apr 13 '16 06:04 uricamic

I'm using Ubuntu 16.04 Beta 2, with GCC 5.3.1 and Python 3.5.1

jiapei100 avatar Apr 13 '16 18:04 jiapei100

Hi @jiapei100,

then I guess the problem might be the version of Python. I never tried to compile with Python 3.+. Could you try to use Python 2.7 instead?

uricamic avatar Apr 14 '16 07:04 uricamic

Hi, Actually, I've also tried this on Ubuntu 14.04 and get the same exact error with python 2.7

botev avatar Apr 14 '16 14:04 botev

Hi @jiapei100 @Botev,

I have updated the library core, could you please try it now (with Python 2.7)? I have checked the build again and it works without problems for me.

uricamic avatar Apr 15 '16 08:04 uricamic

Still the same. Not matter it's python 2. 7 or python 3.5 .

Check my python. jiapei@jiapei-GT72-6QE:/usr/bin$ ls -ls python* 0 lrwxrwxrwx 1 root root 9 Apr 15 01:57 python -> python2.7 0 lrwxrwxrwx 1 root root 9 Mar 27 05:15 python2 -> python2.7 3452 -rwxr-xr-x 1 root root 3533656 Mar 31 05:59 python2.7 0 lrwxrwxrwx 1 root root 33 Mar 31 05:59 python2.7-config -> x86_64-linux-gnu-python2.7-config 0 lrwxrwxrwx 1 root root 16 Dec 9 18:00 python2-config -> python2.7-config 0 lrwxrwxrwx 1 root root 9 Mar 23 04:00 python3 -> python3.5 4336 -rwxr-xr-x 2 root root 4439120 Mar 31 04:51 python3.5 0 lrwxrwxrwx 1 root root 33 Mar 31 04:51 python3.5-config -> x86_64-linux-gnu-python3.5-config 4336 -rwxr-xr-x 2 root root 4439120 Mar 31 04:51 python3.5m 0 lrwxrwxrwx 1 root root 34 Mar 31 04:51 python3.5m-config -> x86_64-linux-gnu-python3.5m-config 0 lrwxrwxrwx 1 root root 16 Mar 23 04:00 python3-config -> python3.5-config 0 lrwxrwxrwx 1 root root 10 Mar 23 04:00 python3m -> python3.5m 0 lrwxrwxrwx 1 root root 17 Mar 23 04:00 python3m-config -> python3.5m-config 0 lrwxrwxrwx 1 root root 16 Dec 9 18:00 python-config -> python2.7-config 0 lrwxrwxrwx 1 root root 58 Mar 25 15:01 pythontex -> ../share/texlive/texmf-dist/scripts/pythontex/pythontex.py

And while configuring clandmark with ccmake ../ out of source building:

` CMake Error at python_interface/CMakeLists.txt:3 (find_package): By not providing "Findclandmark.cmake" in CMAKE_MODULE_PATH this project has asked CMake to find a package configuration file provided by "clandmark", but CMake did not find one.

Could not find a package configuration file provided by "clandmark" with any of the following names:

 clandmarkConfig.cmake
 clandmark-config.cmake

Add the installation prefix of "clandmark" to CMAKE_PREFIX_PATH or set "clandmark_DIR" to a directory containing one of the above files. If "clandmark" provides a separate development package or SDK, be sure it has been installed.

`

Any further suggestions?

Cheers Pei

jiapei100 avatar Apr 15 '16 08:04 jiapei100

Ok, I guess, I will need more information then. Just to check, could you capture screenshots from the complete cmake procedure?

  1. Configure and compile clandmark with BUILD_SHARED=ON, BUILD_EXAMPLES=ON, BUILD_MATLAB_BINDINGS=OFF, BUILD_PYTHON_BINDINGS=OFF
  2. Configure and compile clandmark with BUILD_SHARED=OFF, BUILD_EXAMPLES=OFF, (optionally BUILD_MATLAB_BINDINGS=ON), BUILD_PYTHON_BINDINGS=OFF
  3. Configure and compile clandmark with BUILD_SHARED=ON and BUILD_PYTHON_BINDINGS=ON

set the clandmark_DIR and flandmark_DIR to your build/libclandmark when needed.

uricamic avatar Apr 15 '16 09:04 uricamic

The only thing I tried is: BUILD_MATLAB_BINDINGS=OFF, BUILD_PYTHON_BINDINGS=ON which brings me the errors.

Cheers Pei

jiapei100 avatar Apr 16 '16 05:04 jiapei100

And could you try those I mentioned? I think it is because you are missing the clandmark_DIR and flandmark_DIR, but to be sure, I need to see those screenshots.

uricamic avatar Apr 16 '16 09:04 uricamic

Yes, you are right... clandmark_DIR must be set to "./libclandmark"

Thank you uricamic....

jiapei100 avatar Apr 16 '16 21:04 jiapei100

Sorry, my fault. It looks like it's still the same.

  1. If I disable Python Binding by BUILD_PYTHON_BINDINGS=OFF It's already cached. So, no matter I set clandmark_DIR or not, configure and make will go through.

  2. I tried to enable BUILD_PYTHON_BINDINGS=ON at the very beginning, http://www.longervision.com/questions/clandmark/01_TryToEnablePython.png and see the following error message: http://www.longervision.com/questions/clandmark/02_ConfigureError.png

Then, I set the clandmark_DIR as http://www.longervision.com/questions/clandmark/03_Setting_clandmark_DIR.png but still get errors: http://www.longervision.com/questions/clandmark/04_ConfigureErrorAgain.png

Finally, I even tried to modify CMakeCache.txt http://www.longervision.com/questions/clandmark/05_WhereToSet_clandmark_DIR.png but still get errors: http://www.longervision.com/questions/clandmark/06_ConfigureErrorStill.png

Any further suggestions?

Cheers Pei

jiapei100 avatar Apr 16 '16 23:04 jiapei100

Hi @jiapei100,

could you please try the fullpath to libclandmark folder in clandmark_DIR? Another thing, which I have noticed is that in my case, the CMake asks not only for the clandmark_DIR, but also for the flandmark_DIR, they should be the same, however it is strange, that it is not asked for in your case...

uricamic avatar Apr 17 '16 16:04 uricamic

I tried fullpath as well, still as the issue mentioned Yes, it seems I only have clandmark_DIR, but NO flandmark_DIR

Weird... Pei

jiapei100 avatar Apr 18 '16 06:04 jiapei100

Then, please, check all the CMakeLists.txt files if they are identical to those in repository.

To be more specific, check whether the CMakeLists.txt in the python_interface folder contains this line:

find_package(flandmark REQUIRED)

uricamic avatar Apr 18 '16 06:04 uricamic

This is my CMakeLists.txt under python_interface :

jiapei@jiapei-GT72-6QE:~/Downloads/patternrecognition/clandmark/python_interface$ cat CMakeLists.txt 
# python_interface/CMakeLists.txt

find_package(clandmark REQUIRED)
find_package(flandmark REQUIRED)
include_directories(
  ${CLANDMARK_INCLUDE_DIRS}
  ${FLANDMARK_INCLUDE_DIRS}
)

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
#include_directories( ${PROJECT_SOURCE_DIR}/libclandmark )
include_directories( ${PROJECT_SOURCE_DIR}/3rd_party/rapidxml-1.13 )
include_directories( ${PROJECT_SOURCE_DIR}/3rd_party/CImg-1.5.6 )
execute_process(COMMAND python -c "import numpy as np; print np.get_include()" OUTPUT_VARIABLE NUMPY_INCLUDE)
include_directories(${NUMPY_INCLUDE})


set(PY_NAME_interface python_interface)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wlong-long -Wl,-rpath,'$ORIGIN/'")

# Include the CMake script UseCython.cmake.  This defines add_cython_module().
# Instruction for use can be found at the top of cmake/UseCython.cmake.
include( UseCython )

# propagate precision definition
if(DOUBLE_PRECISION)
    add_definitions( -DDOUBLE_PRECISION=1 )
else(DOUBLE_PRECISION)
    add_definitions( -DDOUBLE_PRECISION=0 )
endif(DOUBLE_PRECISION)


# With CMake, a clean separation can be made between the source tree and the
# build tree.  When all source is compiled, as with pure C/C++, the source is
# no-longer needed in the build tree.  However, with pure *.py source, the
# source is processed directly.  To handle this, we reproduce the availability
# of the source files in the build tree.
add_custom_target( ReplicatePythonSourceTree ALL ${CMAKE_COMMAND} -P
  ${CMAKE_MODULE_PATH}/ReplicatePythonSourceTree.cmake
  ${CMAKE_CURRENT_BINARY_DIR}
  WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} )


# Process the CMakeLists.txt in the 'src' and 'bin' directory.
add_subdirectory( src )
add_subdirectory( bin )

jiapei100 avatar Apr 19 '16 10:04 jiapei100

Hmm, looks the same to me. Maybe you could try to add some message statements and check what is in the ${FLANDMARK_INCLUDE_DIRS} variable.

uricamic avatar Apr 19 '16 10:04 uricamic

I had the same problem. It seems to happen because of the upper cases. after copying and renaming the cmake files like the following I could compile.

ls cmake/Modules/
FindCImg.cmake                   FindCython.cmake                 FindRapidXML.cmake
Findclandmark.cmake              Findflandmark.cmake              ReplicatePythonSourceTree.cmake
FindCLANDMARK.cmake              FindFLANDMARK.cmake              UseCython.cmake

andreas128 avatar Apr 20 '16 07:04 andreas128

Do I have to download a binary named "rectangle-props"? I could only use setup.py when I commented out this file.

  1 from setuptools import setup
  2 from distutils.sysconfig import get_python_lib
  3 import glob
  4 import os
  5 import sys
  6 
  7 if os.path.exists('readme.rst'):
  8     print("""The setup.py script should be executed from the build directory.
  9 
 10 Please see the file 'readme.rst' for further instructions.""")
 11     sys.exit(1)
 12 
 13 
 14 setup(
 15     name = "cythoncmakeexample",
 16     package_dir = {'': 'src'},
 17 #    data_files = [(get_python_lib(), glob.glob('src/*.so')),
 18 #        ('bin', ['bin/rectangle-props'])],
 19     data_files = [(get_python_lib(), glob.glob('src/*.so'))],
 20     author = 'Matt McCormick',
 21     description = 'Use the CMake build system to make Cython modules.',
 22     license = 'Apache',
 23     keywords = 'cmake cython build',
 24     url = 'http://github.com/thewtex/cython-cmake-example',
 25     # test_require = ['nose'],
 26     # zip_safe = False,
 27     )

andreas128 avatar Apr 20 '16 07:04 andreas128

@jiapei100 could you please check whether the renaming of files as suggested by @andreas128 solves the problem for you? If it does, I will rename the files in the repository...

uricamic avatar Apr 20 '16 11:04 uricamic

Hi @andreas128,

I think it is not needed, it remained there for some historical development reasons probably.

uricamic avatar Apr 20 '16 11:04 uricamic

It seems "andreas128's suggestions" does help a bit. Now, I didn't have those warnings due to the upper-case and lower-case issue. However, I meet another issue:

I fact, I checked .../clandmark/python_interface/CMakeLists.txt , and line 14~15 are correct.

execute_process(COMMAND python -c "import numpy as np; print np.get_include()" OUTPUT_VARIABLE NUMPY_INCLUDE)
include_directories(${NUMPY_INCLUDE})

I checked these 2 lines by:

>>> import numpy as np
>>> print(np.get_include())
/usr/local/lib/python3.5/dist-packages/numpy/core/include
>>> exit()
jiapei@jiapei-GT72-6QE:/usr/local/lib/python3.5/dist-packages$ cd /usr/local/lib/python3.5/dist-packages/numpy/core/include
jiapei@jiapei-GT72-6QE:/usr/local/lib/python3.5/dist-packages/numpy/core/include$ ls -ls numpy/ufuncobject.h
16 -rw-r--r-- 1 root staff 12323 Apr 20 10:56 numpy/ufuncobject.h

However, "make" still results in the following error message:

/home/jiapei/Downloads/patternrecognition/clandmark/build/python_interface/src/py_featurePool.cxx:283:31: fatal error: numpy/ufuncobject.h: No such file or directory compilation terminated. python_interface/src/CMakeFiles/py_featurePool.dir/build.make:70: recipe for target 'python_interface/src/CMakeFiles/py_featurePool.dir/py_featurePool.cxx.o' failed make[2]: *** [python_interface/src/CMakeFiles/py_featurePool.dir/py_featurePool.cxx.o] Error 1 CMakeFiles/Makefile2:339: recipe for target 'python_interface/src/CMakeFiles/py_featurePool.dir/all' failed make[1]: *** [python_interface/src/CMakeFiles/py_featurePool.dir/all] Error 2 Makefile:127: recipe for target 'all' failed make: *** [all] Error 2

And, if I ignore python building, by ticking off BUILD_PYTHON_BINDINGS, and do sudo python setup.py install directly from within python_interface subdirectory, I got the following error message: error: can't copy 'bin/rectangle-props': doesn't exist or not a regular file

Oh, BTW, my numpy version

>>> import numpy
>>> numpy.__version__
'1.11.0'

So, any further suggestions?

Cheers Pei

jiapei100 avatar Apr 20 '16 18:04 jiapei100

Hi @jiapei100,

I am not sure, since I am not a Python expert, but I think the problem might be the Python version.

I was checking the build system only for Python 2.7, while in your post, I see that you are still referring to Python 3.5. So, the question is, do you use Python 2.7 in CMake configuration? If you do, do you have numpy for Python 2.7 as well?

Best,

Michal

uricamic avatar Apr 21 '16 07:04 uricamic