mapillary / OpenSfM

Open source Structure-from-Motion pipeline
https://www.opensfm.org/
BSD 2-Clause "Simplified" License
3.39k stars 859 forks source link

ImportError: No module named csfm #179

Closed dgriffiths3 closed 7 years ago

dgriffiths3 commented 7 years ago

Since installing OpenCV3 I am having the following issue when running OpenSfM:

MacBook-Pro:OpenSfM davidgriffiths$ bin/opensfm_run_all /Users/davidgriffiths/OpenSfM/data/berlin
Traceback (most recent call last):
  File "/Users/davidgriffiths/OpenSfM/bin/opensfm", line 10, in <module>
    from opensfm import commands
  File "/Users/davidgriffiths/OpenSfM/opensfm/commands/__init__.py", line 2, in <module>
    import extract_metadata
  File "/Users/davidgriffiths/OpenSfM/opensfm/commands/extract_metadata.py", line 5, in <module>
    from opensfm import dataset
  File "/Users/davidgriffiths/OpenSfM/opensfm/dataset.py", line 12, in <module>
    from opensfm import io
  File "/Users/davidgriffiths/OpenSfM/opensfm/io.py", line 10, in <module>
    from opensfm import features
  File "/Users/davidgriffiths/OpenSfM/opensfm/features.py", line 7, in <module>
    import csfm
ImportError: No module named csfm

My system is:

OS: Mac OS Sierra 10.12.5 Python: 2.7.13 and 3.6.1 OpenCV: 2.4.13.2 3.2.0

If it is of any assistance the relevant section in the CMakeLists.txt file shows:

# Python wrapper
add_library(csfm SHARED csfm.cc)
target_link_libraries(csfm
    ${OpenCV_LIBS}
    ${GFLAGS_LIBRARY}
    ${GLOG_LIBRARY}
    ${CERES_LIBRARIES}
    ${LAPACK_LIBRARIES}
    ${SUITESPARSE_LIBRARIES}
    ${Boost_LIBRARIES}
    vl
    akaze
)
set_target_properties(csfm PROPERTIES
    PREFIX ""
    SUFFIX ".so"
    LIBRARY_OUTPUT_DIRECTORY "${opensfm_SOURCE_DIR}/.."
)
if(APPLE)
    set_target_properties(csfm PROPERTIES
        LINK_FLAGS "-undefined dynamic_lookup"
    )
else()
    target_link_libraries(csfm
        ${PYTHON_LIBRARIES}
    )
endif()

I would like to keep OpenCV3 functional on my system as I use it for lots of other things, can I make this work. I have left OpenCV 2.4.13.2 installed.

Many Thanks.

dgriffiths3 commented 7 years ago

On further inspection I have noticed I am getting a lot of errors when building OpenSfM with python setup.py build. The terminal output is as follows:

Configuring...
-- The C compiler identification is AppleClang 8.1.0.8020042
-- The CXX compiler identification is AppleClang 8.1.0.8020042
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Try OpenMP C flag = [-fopenmp=libomp]
-- Performing Test OpenMP_FLAG_DETECTED
-- Performing Test OpenMP_FLAG_DETECTED - Failed
-- Try OpenMP C flag = [ ]
-- Performing Test OpenMP_FLAG_DETECTED
-- Performing Test OpenMP_FLAG_DETECTED - Failed
-- Try OpenMP C flag = [-fopenmp]
-- Performing Test OpenMP_FLAG_DETECTED
-- Performing Test OpenMP_FLAG_DETECTED - Failed
-- Try OpenMP C flag = [/openmp]
-- Performing Test OpenMP_FLAG_DETECTED
-- Performing Test OpenMP_FLAG_DETECTED - Failed
-- Try OpenMP C flag = [-Qopenmp]
-- Performing Test OpenMP_FLAG_DETECTED
-- Performing Test OpenMP_FLAG_DETECTED - Failed
-- Try OpenMP C flag = [-openmp]
-- Performing Test OpenMP_FLAG_DETECTED
-- Performing Test OpenMP_FLAG_DETECTED - Failed
-- Try OpenMP C flag = [-xopenmp]
-- Performing Test OpenMP_FLAG_DETECTED
-- Performing Test OpenMP_FLAG_DETECTED - Failed
-- Try OpenMP C flag = [+Oopenmp]
-- Performing Test OpenMP_FLAG_DETECTED
-- Performing Test OpenMP_FLAG_DETECTED - Failed
-- Try OpenMP C flag = [-qsmp]
-- Performing Test OpenMP_FLAG_DETECTED
-- Performing Test OpenMP_FLAG_DETECTED - Failed
-- Try OpenMP C flag = [-mp]
-- Performing Test OpenMP_FLAG_DETECTED
-- Performing Test OpenMP_FLAG_DETECTED - Failed
-- Try OpenMP CXX flag = [-fopenmp=libomp]
-- Performing Test OpenMP_FLAG_DETECTED
-- Performing Test OpenMP_FLAG_DETECTED - Failed
-- Try OpenMP CXX flag = [ ]
-- Performing Test OpenMP_FLAG_DETECTED
-- Performing Test OpenMP_FLAG_DETECTED - Failed
-- Try OpenMP CXX flag = [-fopenmp]
-- Performing Test OpenMP_FLAG_DETECTED
-- Performing Test OpenMP_FLAG_DETECTED - Failed
-- Try OpenMP CXX flag = [/openmp]
-- Performing Test OpenMP_FLAG_DETECTED
-- Performing Test OpenMP_FLAG_DETECTED - Failed
-- Try OpenMP CXX flag = [-Qopenmp]
-- Performing Test OpenMP_FLAG_DETECTED
-- Performing Test OpenMP_FLAG_DETECTED - Failed
-- Try OpenMP CXX flag = [-openmp]
-- Performing Test OpenMP_FLAG_DETECTED
-- Performing Test OpenMP_FLAG_DETECTED - Failed
-- Try OpenMP CXX flag = [-xopenmp]
-- Performing Test OpenMP_FLAG_DETECTED
-- Performing Test OpenMP_FLAG_DETECTED - Failed
-- Try OpenMP CXX flag = [+Oopenmp]
-- Performing Test OpenMP_FLAG_DETECTED
-- Performing Test OpenMP_FLAG_DETECTED - Failed
-- Try OpenMP CXX flag = [-qsmp]
-- Performing Test OpenMP_FLAG_DETECTED
-- Performing Test OpenMP_FLAG_DETECTED - Failed
-- Try OpenMP CXX flag = [-mp]
-- Performing Test OpenMP_FLAG_DETECTED
-- Performing Test OpenMP_FLAG_DETECTED - Failed
-- Could NOT find OpenMP (missing:  OpenMP_C_FLAGS OpenMP_CXX_FLAGS) 
-- Looking for dgemm_
-- Looking for dgemm_ - found
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - found
-- Found Threads: TRUE  
-- A library with BLAS API found.
-- Looking for cheev_
-- Looking for cheev_ - found
-- A library with LAPACK API found.
-- A library with BLAS API found.
-- Failed to find SuiteSparse - Did not find AMD library (required SuiteSparse component).
-- Failed to find SuiteSparse - Did not find AMD header (required SuiteSparse component).
-- Failed to find SuiteSparse - Did not find CAMD library (required SuiteSparse component).
-- Failed to find SuiteSparse - Did not find CAMD header (required SuiteSparse component).
-- Failed to find SuiteSparse - Did not find COLAMD library (required SuiteSparse component).
-- Failed to find SuiteSparse - Did not find COLAMD header (required SuiteSparse component).
-- Failed to find SuiteSparse - Did not find CCOLAMD library (required SuiteSparse component).
-- Failed to find SuiteSparse - Did not find CCOLAMD header (required SuiteSparse component).
-- Failed to find SuiteSparse - Did not find CHOLMOD library (required SuiteSparse component).
-- Failed to find SuiteSparse - Did not find CHOLMOD header (required SuiteSparse component).
-- Failed to find SuiteSparse - Did not find SuiteSparseQR library (required SuiteSparse component).
-- Failed to find SuiteSparse - Did not find SUITESPARSEQR header (required SuiteSparse component).
-- Failed to find SuiteSparse - Failed to find either: SuiteSparse_config header & library (should be present in all SuiteSparse >= v4 installs), or UFconfig header (should be present in all SuiteSparse < v4 installs).
-- Did not find METIS library (optional SuiteSparse dependency)
-- Failed to find some/all required components of SuiteSparse. (missing:  AMD_FOUND CAMD_FOUND COLAMD_FOUND CCOLAMD_FOUND CHOLMOD_FOUND SUITESPARSEQR_FOUND SUITESPARSE_VERSION) 
-- Found Eigen: /usr/local/include/eigen3 (found version "3.3.3") 
-- Could NOT find ceres (missing:  CERES_LIBRARY CERES_INCLUDE_DIR) 
-- No preference for use of exported gflags CMake configuration set, and no hints for include/library directories provided. Defaulting to preferring an installed/exported gflags CMake configuration if available.
-- Failed to find installed gflags CMake configuration, searching for gflags build directories exported with CMake.
-- Failed to find an installed/exported CMake configuration for gflags, will perform search for installed gflags components.
CMake Error at cmake/FindGflags.cmake:118 (message):
  Failed to find gflags - Could not find gflags include directory, set
  GFLAGS_INCLUDE_DIR to directory containing gflags/gflags.h
Call Stack (most recent call first):
  cmake/FindGflags.cmake:455 (gflags_report_not_found)
  CMakeLists.txt:40 (find_package)

CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
CERES_INCLUDE_DIR (ADVANCED)
   used as include directory in directory /Users/davidgriffiths/OpenSfM/opensfm/src
   used as include directory in directory /Users/davidgriffiths/OpenSfM/opensfm/src

-- Configuring incomplete, errors occurred!
See also "/Users/davidgriffiths/OpenSfM/cmake_build/CMakeFiles/CMakeOutput.log".
See also "/Users/davidgriffiths/OpenSfM/cmake_build/CMakeFiles/CMakeError.log".
Compiling extension...
make: *** No targets specified and no makefile found.  Stop.
Building package
running build
running build_py
creating build
creating build/lib
creating build/lib/opensfm
copying opensfm/__init__.py -> build/lib/opensfm
copying opensfm/align.py -> build/lib/opensfm
copying opensfm/config.py -> build/lib/opensfm
copying opensfm/context.py -> build/lib/opensfm
copying opensfm/dataset.py -> build/lib/opensfm
copying opensfm/dense.py -> build/lib/opensfm
copying opensfm/exif.py -> build/lib/opensfm
copying opensfm/features.py -> build/lib/opensfm
copying opensfm/geo.py -> build/lib/opensfm
copying opensfm/geotag_from_gpx.py -> build/lib/opensfm
copying opensfm/io.py -> build/lib/opensfm
copying opensfm/matching.py -> build/lib/opensfm
copying opensfm/mesh.py -> build/lib/opensfm
copying opensfm/multiview.py -> build/lib/opensfm
copying opensfm/reconstruction.py -> build/lib/opensfm
copying opensfm/sensors.py -> build/lib/opensfm
copying opensfm/transformations.py -> build/lib/opensfm
copying opensfm/types.py -> build/lib/opensfm
copying opensfm/unionfind.py -> build/lib/opensfm
copying opensfm/video.py -> build/lib/opensfm
creating build/lib/opensfm/commands
copying opensfm/commands/__init__.py -> build/lib/opensfm/commands
copying opensfm/commands/compute_depthmaps.py -> build/lib/opensfm/commands
copying opensfm/commands/create_tracks.py -> build/lib/opensfm/commands
copying opensfm/commands/detect_features.py -> build/lib/opensfm/commands
copying opensfm/commands/export_openmvs.py -> build/lib/opensfm/commands
copying opensfm/commands/export_ply.py -> build/lib/opensfm/commands
copying opensfm/commands/export_visualsfm.py -> build/lib/opensfm/commands
copying opensfm/commands/extract_metadata.py -> build/lib/opensfm/commands
copying opensfm/commands/match_features.py -> build/lib/opensfm/commands
copying opensfm/commands/mesh.py -> build/lib/opensfm/commands
copying opensfm/commands/reconstruct.py -> build/lib/opensfm/commands
copying opensfm/commands/undistort.py -> build/lib/opensfm/commands
creating build/lib/opensfm/data
copying opensfm/data/sensor_data.json -> build/lib/opensfm/data
running build_scripts
creating build/scripts-2.7
copying bin/opensfm_run_all -> build/scripts-2.7
copying and adjusting bin/opensfm -> build/scripts-2.7
changing mode of build/scripts-2.7/opensfm from 644 to 755

I am getting the impression this is being caused due to a PATH issue, is there a way to tell the cmake file where to find the required files?

I have the following paths in my ~/.bash_profile:

export PATH=/Users/davidgriffiths/vsfm/bin:$PATH
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/Users/davidgriffiths
export PYTHONPATH=/usr/local/lib/python2.7/site-packages:$PYTHONPATH
export PATH=/usr/local/bin:$PATH
export PATH=/usr/local/share/python:$PATH

Also if it is worth noting, I have installed everything using Homebrew.

Many Thanks.

paulinus commented 7 years ago

The problems on the messages seem related to not finding Ceres and other libs, but not related to OpenCV

Were you able to build opensfm before?

dgriffiths3 commented 7 years ago

I have have managed to both build and run the software now. I installed OpenMPI using HomeBrew, and I don't think this was detected by the compiler in Mac OS 10.12.5. To get it working I needed to direct the C and CXX flags using the following before running the setup.py file.

export CC=/usr/local/bin/gcc-7
export CXX=/usr/local/bin/g++-7

I also added the following to the ~/.bashrc file.

alias gcc='gcc-7'

After this everything worked as before.