uzh-rpg / flightmare

An Open Flexible Quadrotor Simulator
https://uzh-rpg.github.io/flightmare/
Other
980 stars 342 forks source link

flightmare installation issues #211

Open abdul-mannan-khan opened 1 month ago

abdul-mannan-khan commented 1 month ago

Hello, Thank you so much for sharing this amazing work. Really grateful for this. I tried to install it following the installation guides give here and got following error:

  Building wheel for flightgym (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: /home/mannan/anaconda3/envs/flightmare/bin/python -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-req-build-m5n1lx4v/setup.py'"'"'; __file__='"'"'/tmp/pip-req-build-m5n1lx4v/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-xx5p8su_
       cwd: /tmp/pip-req-build-m5n1lx4v/
  Complete output (73 lines):
  running bdist_wheel
  running build
  running build_ext
  -- The C compiler identification is GNU 9.4.0
  -- The CXX compiler identification is GNU 9.4.0
  -- Check for working C compiler: /usr/bin/cc
  -- Check for working C compiler: /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: /usr/bin/c++
  -- Check for working CXX compiler: /usr/bin/c++ -- works
  -- Detecting CXX compiler ABI info
  -- Detecting CXX compiler ABI info - done
  -- Detecting CXX compile features
  -- Detecting CXX compile features - done
  -- ======================  !Flightmare!  ======================
  -- ======> Setup Dependencies
  -- Using system provided Eigen.
  /usr/include/eigen3
  -- Eigen3 include dir: /usr/include/eigen3
  -- Getting Pybind11...
  Cloning into 'pybind11-src'...
  Already on 'master'
  -- Pybind11 downloaded!
  -- pybind11 v2.14.0 dev1
  CMake Error at /usr/share/cmake-3.16/Modules/FindPackageHandleStandardArgs.cmake:146 (message):
    Could NOT find PythonInterp: Found unsuitable version "3.6.13", but
    required is at least "3.8" (found
    /home/mannan/anaconda3/envs/flightmare/bin/python)
  Call Stack (most recent call first):
    /usr/share/cmake-3.16/Modules/FindPackageHandleStandardArgs.cmake:391 (_FPHSA_FAILURE_MESSAGE)
    /usr/share/cmake-3.16/Modules/FindPythonInterp.cmake:169 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
    externals/pybind11-src/tools/FindPythonLibsNew.cmake:114 (find_package)
    externals/pybind11-src/tools/pybind11Tools.cmake:50 (find_package)
    externals/pybind11-src/tools/pybind11Common.cmake:202 (include)
    externals/pybind11-src/CMakeLists.txt:249 (include)

  -- Configuring incomplete, errors occurred!
  See also "/tmp/pip-req-build-m5n1lx4v/build/temp.linux-x86_64-3.6/CMakeFiles/CMakeOutput.log".
  Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "/tmp/pip-req-build-m5n1lx4v/setup.py", line 106, in <module>
      zip_safe=False,
    File "/home/mannan/anaconda3/envs/flightmare/lib/python3.6/site-packages/setuptools/__init__.py", line 153, in setup
      return distutils.core.setup(**attrs)
    File "/home/mannan/anaconda3/envs/flightmare/lib/python3.6/distutils/core.py", line 148, in setup
      dist.run_commands()
    File "/home/mannan/anaconda3/envs/flightmare/lib/python3.6/distutils/dist.py", line 955, in run_commands
      self.run_command(cmd)
    File "/home/mannan/anaconda3/envs/flightmare/lib/python3.6/distutils/dist.py", line 974, in run_command
      cmd_obj.run()
    File "/home/mannan/anaconda3/envs/flightmare/lib/python3.6/site-packages/wheel/bdist_wheel.py", line 299, in run
      self.run_command('build')
    File "/home/mannan/anaconda3/envs/flightmare/lib/python3.6/distutils/cmd.py", line 313, in run_command
      self.distribution.run_command(command)
    File "/home/mannan/anaconda3/envs/flightmare/lib/python3.6/distutils/dist.py", line 974, in run_command
      cmd_obj.run()
    File "/home/mannan/anaconda3/envs/flightmare/lib/python3.6/distutils/command/build.py", line 135, in run
      self.run_command(cmd_name)
    File "/home/mannan/anaconda3/envs/flightmare/lib/python3.6/distutils/cmd.py", line 313, in run_command
      self.distribution.run_command(command)
    File "/home/mannan/anaconda3/envs/flightmare/lib/python3.6/distutils/dist.py", line 974, in run_command
      cmd_obj.run()
    File "/tmp/pip-req-build-m5n1lx4v/setup.py", line 59, in run
      self.build_extension(ext)
    File "/tmp/pip-req-build-m5n1lx4v/setup.py", line 89, in build_extension
      cmake_args, cwd=self.build_temp, env=env)
    File "/home/mannan/anaconda3/envs/flightmare/lib/python3.6/subprocess.py", line 311, in check_call
      raise CalledProcessError(retcode, cmd)
  subprocess.CalledProcessError: Command '['cmake', '/tmp/pip-req-build-m5n1lx4v', '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=/tmp/pip-req-build-m5n1lx4v/build/lib.linux-x86_64-3.6/', '-DPYTHON_EXECUTABLE=/home/mannan/anaconda3/envs/flightmare/bin/python', '-DCMAKE_BUILD_TYPE=Release']' returned non-zero exit status 1.
  ----------------------------------------
  ERROR: Failed building wheel for flightgym
  Running setup.py clean for flightgym

To resolve this issue, I changed the conda environment from Python 3.6 to 3.8. Then, I got an issue of googletest repository. I downloaded it locally. Then, I hit an issue in CMakeLists.txt file in flightlib. So, I modifed it to:

cmake_minimum_required(VERSION 3.0)

project(flightlib VERSION 0.1.0)

message(STATUS "======================  !Flightmare!  ======================")

################################################################################
# Options
################################################################################
option(BUILD_TESTS "Building the tests" ON)
option(BUILD_UNITY_BRIDGE_TESTS "Building the Unity Bridge tests" ON)
option(BUILD_BENCH "Building the benchmark." OFF)
option(ENABLE_FAST "Build with optimizations for speed" ON)
option(ENABLE_BLAS "Build using BLAS and LAPACK libraries" OFF)
option(ENABLE_PARALLEL "Build using openmp parallelization" ON)
option(EIGEN_FROM_SYSTTEM "Use the system-provided Eigen" ON)
set(
  EIGEN_ALTERNATIVE "" CACHE STRING
  "Path to alternative Eigen, autodownload if blank"
)

################################################################################
# Finding Dependencies
################################################################################

message(STATUS "======> Setup Dependencies")
if(EIGEN_FROM_SYSTTEM)
  find_package(Eigen3 3.3.4 QUIET)
  if(EIGEN3_FOUND)
    message(STATUS "Using system provided Eigen.")
    message(${EIGEN3_INCLUDE_DIR})
  else()
    message(STATUS "No sufficient Eigen version (3.3.4) found.")
    message(STATUS "Restoring to download Eigen sources.")
    include(cmake/eigen.cmake)
  endif()
elseif(EIGEN_ALTERNATIVE STREQUAL "")
  include(cmake/eigen.cmake)
else()
  set(EIGEN_INCLUDE_DIR ${EIGEN_ALTERNATIVE})
endif()

message(STATUS "Eigen3 include dir: ${EIGEN3_INCLUDE_DIR}")

# Including dependencies 
include(cmake/pybind11.cmake)
include(cmake/yaml.cmake)

# Including dependencies 
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
find_package(OpenMP REQUIRED)

if(ENABLE_BLAS)
  set(BLA_VENDOR "Generic")
  find_package(BLAS REQUIRED)
  if(BLAS_FOUND)
    message(STATUS "Found BLAS: ${BLAS_LIBRARIES}")
  else()
    message(ERROR "Could not enable BLAS because BLAS was not found")
  endif()
  find_package(LAPACK REQUIRED)
  if(LAPACK_FOUND)
    message(STATUS "Found Lapack: ${LAPACK_LIBRARIES}")
  else()
    message(ERROR "Could not enable LAPACK because LAPACK was not found")
  endif()
endif()

# Check for ccache
if(NOT DEFINED CATKIN_DEVEL_PREFIX)
  find_program(CCACHE_PROGRAM ccache)
  if(CCACHE_PROGRAM)
    set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}")
  else()
    message(INFO "Build time could be improved with ccache!")
    message(INFO "    sudo apt install ccache")
  endif()
endif()

################################################################################
# Setup Compilation
################################################################################
message(STATUS "======> Setup Compilation")

add_definitions(-DEIGEN_STACK_ALLOCATION_LIMIT=1048576)
include_directories(${EIGEN_INCLUDE_DIR} "tests")
include_directories(${OpenCV_INCLUDE_DIRS})

# Set default build type
if (NOT EXISTS ${CMAKE_BINARY_DIR}/CMakeCache.txt)
  if (NOT CMAKE_BUILD_TYPE)
    set(CMAKE_BUILD_TYPE "Release" CACHE STRING "" FORCE)
  endif()
endif()

# Add c++ flags 
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -fPIC -Wall -DNDEBUG  -fopenmp")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -fPIC -Wall -g -fopenmp")
set(CMAKE_CXX_STANDARD 17)

# Architectural flags
if("${CMAKE_HOST_SYSTEM_PROCESSOR}" STREQUAL "armv7l")
  message(STATUS "Using ARMv7 optimized flags!")
  set(CMAKE_CXX_ARCH_FLAGS " -Wno-psabi -march=armv7-a -mfpu=neon -mfloat-abi=hard -funsafe-math-optimizations")
elseif("${CMAKE_HOST_SYSTEM_PROCESSOR}" STREQUAL "aarch64")
  message(STATUS "Using ARM aarch64 optimized flags!")
  set(CMAKE_CXX_ARCH_FLAGS " -Wno-psabi -march=armv8-a+crypto -mcpu=cortex-a57+crypto")
else()
  set(CMAKE_CXX_ARCH_FLAGS " -march=native")
endif()

# Optimized flags
if(ENABLE_FAST)
  message(STATUS "Enabling fast optimization flags!")
  set(CMAKE_CXX_FAST_FLAGS " -Ofast")
else()
  set(CMAKE_CXX_FAST_FLAGS " -O0")
endif()

# BLAS Flags
if(BLAS_FOUND AND LAPACK_FOUND)
  message(STATUS "Enabling BLAS and LAPACK")
  set(CMAKE_CXX_BLAS_FLAGS " -DEIGEN_USE_BLAS -DEIGEN_USE_LAPACK -DEIGEN_USE_LAPACKE")
else()
  set(CMAKE_CXX_BLAS_FLAGS "")
endif()

# Summarize Flags
set(CMAKE_CXX_FLAGS_RELEASE
  "${CMAKE_CXX_FLAGS_RELEASE} ${CMAKE_CXX_FAST_FLAGS} ${CMAKE_CXX_ARCH_FLAGS} ${CMAKE_CXX_PAR_FLAGS}")
string(REPLACE "-DNDEBUG" "" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
message(STATUS "The activated CXX RELEASE configuration is:\n ${CMAKE_CXX_FLAGS_RELEASE}")
message(STATUS "The activated CXX DEBUG configuration is:\n ${CMAKE_CXX_FLAGS_DEBUG}")

################################################################################
# Specify Build Resources
################################################################################
message(STATUS "======>  Setup Build  ")

# Create file lists for flightlib source
file(GLOB_RECURSE FLIGHTLIB_SOURCES
  src/bridges/*.cpp
  src/dynamics/*.cpp
  src/objects/*.cpp
  src/sensors/*.cpp
  src/envs/*.cpp
  src/common/*.cpp
)

# Create file lists for flightlib tests
file(GLOB_RECURSE FLIGHTLIB_TEST_SOURCES
  tests/dynamics/*.cpp
  tests/objects/*.cpp
  tests/sensors/*.cpp  
  tests/envs/*.cpp
  tests/common/*.cpp
)

# Create file lists for flightlib_gym source 
file(GLOB_RECURSE FLIGHTLIB_GYM_SOURCES
  src/wrapper/*.cpp 
)

# Create file lists for flightlib_gym tests
file(GLOB_RECURSE FLIGHTLIB_GYM_TEST_SOURCES
  tests/wrapper/*.cpp
)

# Create file lists for flightlib_unity_bridge tests
file(GLOB_RECURSE FLIGHTLIB_UNITY_BRIDGE_TEST_SOURCES
  tests/bridges/*.cpp
)

################################################################################
# Optional Catkin Build
################################################################################

if(DEFINED CATKIN_DEVEL_PREFIX)
  message(STATUS "======>  Building with -- catkin -- ")
  include(cmake/catkin.cmake)
  return()
endif()

################################################################################
# Setup Build
################################################################################

# Setup Testing and Benchmark
if(BUILD_TESTS OR BUILD_BENCH)
  # Point to the local googletest directory
  add_subdirectory(${CMAKE_SOURCE_DIR}/googletest)
  enable_testing()
endif()

# Library and Executables
include_directories(include)

if(NOT FLIGHTLIB_SOURCES)
  set(LIBRARY_NAME)
else()
  # flightlib
  add_library(${PROJECT_NAME} ${FLIGHTLIB_SOURCES})
  target_link_libraries(${PROJECT_NAME} PRIVATE
    ${OpenCV_LIBRARIES}
    yaml-cpp
    zmq
    zmqpp
    stdc++fs)
  set(LIBRARY_NAME ${PROJECT_NAME})
  set_target_properties(${PROJECT_NAME} PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
endif()

if(FLIGHTLIB_GYM_SOURCES)
  # flightlib_gym (python3 binding with Pybind11)
  pybind11_add_module(flightgym MODULE 
    ${FLIGHTLIB_GYM_SOURCES})
  if(EIGEN3_FOUND)
    target_include_directories(flightgym PRIVATE
      # ${PROJECT_SOURCE_DIR}/externals/pybind11-src/include
      ${PYBIND11_INCLUDE_DIR}
      ${PROJECT_SOURCE_DIR}/include
      ${EIGEN3_INCLUDE_DIR})  
  else()
    target_include_directories(flightgym PRIVATE
      # ${PROJECT_SOURCE_DIR}/externals/pybind11-src/include
      ${PYBIND11_INCLUDE_DIR}
      ${PROJECT_SOURCE_DIR}/externals/eigen/eigen3 #pybind11 use #include <Eigen/Core>, however, flightmare use #include <eigen3/Eigen/Core>
      ${PROJECT_SOURCE_DIR}/include)  
  endif()
  target_link_libraries(flightgym PRIVATE ${LIBRARY_NAME} )
endif()

if(ENABLE_BLAS AND BLAS_FOUND AND LAPACK_FOUND)
  message(STATUS "Linking standard BLAS ${BLAS_LIBRARIES}")
  target_link_libraries(${LIBRARY_NAME}
    ${BLAS_LIBRARIES}
    ${LAPACK_LIBRARIES}
    ${LAPACKE_LIBRARIES}
  )
endif()

# Build tests for flightlib gym wrapper
if(BUILD_TESTS AND FLIGHTLIB_GYM_TEST_SOURCES)
  add_executable(test_gym ${FLIGHTLIB_GYM_TEST_SOURCES})
  target_link_libraries(test_gym
    ${LIBRARY_NAME}
    gtest
    gtest_main)
add_test(test_gym test_gym)
endif()

# Build tests for flightlib
if(BUILD_TESTS AND FLIGHTLIB_TEST_SOURCES)
  add_executable(test_lib ${FLIGHTLIB_TEST_SOURCES})
  target_link_libraries(test_lib PUBLIC
    ${LIBRARY_NAME}
    gtest
    gtest_main)
add_test(test_lib test_lib)
endif()

# Build tests for flightlib unity bridge
if(BUILD_UNITY_BRIDGE_TESTS AND FLIGHTLIB_UNITY_BRIDGE_TEST_SOURCES)
  add_executable(test_unity_bridge ${FLIGHTLIB_UNITY_BRIDGE_TEST_SOURCES})
  target_link_libraries(test_unity_bridge PUBLIC
    ${LIBRARY_NAME}
    gtest
    gtest_main)
add_test(test_unity_bridge test_unity_bridge)
endif()

message(STATUS "================  !Done. No more nightmare!  ================")

Then, I also faced issue with setup.py file in flightlib. So, I changed it to

import os
import glob
import shutil
import re
import sys
import platform
import subprocess

from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext
from distutils.version import LooseVersion

class CMakeExtension(Extension):
    def __init__(self, name, sourcedir=''):
        Extension.__init__(self, name, sources=[])
        self.sourcedir = os.path.abspath(sourcedir)

class CMakeBuild(build_ext):
    def run(self):
        FLIGHTLIB_EXTERNAL_FILES = os.environ["FLIGHTMARE_PATH"] + \
            "/flightlib/externals/"
        # --------------------------------
        # remove cached external files
        # a hack to solve some cmake error when using "pip install ."
        try:
            for i, p in enumerate(glob.glob(os.path.join(FLIGHTLIB_EXTERNAL_FILES, "*"))):
                shutil.rmtree(p)
                print("Removing some cache file: ", p)
        except:
            pass
        FLIGHTLIB_BUILD_FILES = os.environ["FLIGHTMARE_PATH"] + \
            "/flightlib/build/"
        # --------------------------------
        # remove cached files
        # a hack to solve some cmake error when using "pip install ."
        try:
            for i, p in enumerate(glob.glob(os.path.join(FLIGHTLIB_BUILD_FILES, "*"))):
                shutil.rmtree(p)
                print("Removing some cache file: ", p)
        except:
            pass
        # --------------------------------

        try:
            out = subprocess.check_output(['cmake', '--version'])
        except OSError:
            raise RuntimeError("CMake must be installed to build the following extensions: " +
                               ", ".join(e.name for e in self.extensions))

        if platform.system() == "Windows":
            cmake_version = LooseVersion(
                re.search(r'version\s*([\d.]+)', out.decode()).group(1))
            if cmake_version < '3.1.0':
                raise RuntimeError("CMake >= 3.1.0 is required on Windows")

        for ext in self.extensions:
            self.build_extension(ext)

    def build_extension(self, ext):
        extdir = os.path.abspath(os.path.dirname(
            self.get_ext_fullpath(ext.name)))
        # required for auto-detection of auxiliary "native" libs
        if not extdir.endswith(os.path.sep):
            extdir += os.path.sep
        cmake_args = ['-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + extdir,
                      '-DPYTHON_EXECUTABLE=' + sys.executable]

        cfg = 'Debug' if self.debug else 'Release'
        build_args = ['--config', cfg]

        if platform.system() == "Windows":
            cmake_args += [
                '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{}={}'.format(cfg.upper(), extdir)]
            if sys.maxsize > 2**32:
                cmake_args += ['-A', 'x64']
            build_args += ['--', '/m']
        else:
            cmake_args += ['-DCMAKE_BUILD_TYPE=' + cfg]
            build_args += ['--', '-j4']

        env = os.environ.copy()
        env['CXXFLAGS'] = '{} -DVERSION_INFO=\\"{}\\"'.format(env.get('CXXFLAGS', ''),
                                                              self.distribution.get_version())
        if not os.path.exists(self.build_temp):
            os.makedirs(self.build_temp)
        subprocess.check_call(['cmake', ext.sourcedir] +
                              cmake_args, cwd=self.build_temp, env=env)
        subprocess.check_call(['cmake', '--build', '.'] +
                              build_args, cwd=self.build_temp)

setup(
    name='flightgym',
    version='0.0.1',
    author='Yunlong Song',
    author_email='song@ifi.uzh.ch',
    description='Flightmare: A Quadrotor Simulator.',
    long_description='',
    ext_modules=[CMakeExtension('flightlib')],
    install_requires=['gym==0.11', 'ruamel.yaml',
                      'numpy', 'stable_baselines==2.10.1'],
    cmdclass=dict(build_ext=CMakeBuild),
    include_package_data=True,
    zip_safe=False,
)

Then, I ran into issues with dependencies, i resolved them by running

pip install oauthlib>=3.0.0 requests-oauthlib

Finally, I got successful installation. However, when I tried to run

python3 run_drone_control.py --train 0 --render 1

I got a problem ModuleNotFoundError: No module named 'tensorflow'. Upon further reading, I found that I cannot install Tensorflow 1 version because it is not compatible for Python 3.8. This repository is using Tensorflow 1. In conclusion, this repository is not working Python 3.6 and if we use Python 3.8, we get issues with Tensorflow 1. Any solution? Thank you.

lakshmikanth-nageswar commented 1 month ago

Hi, I am facing similar issue and am unable to resolve it yet. Could you please let me know if you find a solution.

Thanks!

abdul-mannan-khan commented 1 month ago

No. David Scaramuzza team needs to take a look at it as installation is very old.