Tinker-Twins/AutoDRIVE

Python package problem

Marnonel6 opened this issue · 2 comments

Hi,

Thank you for the great simulator! I am trying to use the autodrive ros2 api, but get this problem when I try to install the python packages:

marno@arragon:~/projects/AutoDRIVE/ros2_ws$ pip3 install -r requirements.txt 
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: eventlet==0.33.3 in /home/marno/.local/lib/python3.10/site-packages (from -r requirements.txt (line 1)) (0.33.3)
Requirement already satisfied: Flask==1.1.1 in /home/marno/.local/lib/python3.10/site-packages (from -r requirements.txt (line 2)) (1.1.1)
Requirement already satisfied: Flask-SocketIO==4.1.0 in /home/marno/.local/lib/python3.10/site-packages (from -r requirements.txt (line 3)) (4.1.0)
Requirement already satisfied: python-socketio==4.2.0 in /home/marno/.local/lib/python3.10/site-packages (from -r requirements.txt (line 4)) (4.2.0)
Requirement already satisfied: python-engineio==3.13.0 in /home/marno/.local/lib/python3.10/site-packages (from -r requirements.txt (line 5)) (3.13.0)
Collecting greenlet==1.0.0
  Using cached greenlet-1.0.0.tar.gz (84 kB)
  Preparing metadata (setup.py) ... done
Collecting gevent==21.1.2
  Using cached gevent-21.1.2.tar.gz (5.9 MB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... error
  error: subprocess-exited-with-error
  
  × Getting requirements to build wheel did not run successfully.
  │ exit code: 1
  ╰─> [57 lines of output]
      Compiling src/gevent/resolver/cares.pyx because it changed.
      [1/1] Cythonizing src/gevent/resolver/cares.pyx
      performance hint: src/gevent/libev/corecext.pyx:1325:5: Exception check on '_syserr_cb' will always require the GIL to be acquired.
      Possible solutions:
          1. Declare the function as 'noexcept' if you control the definition and you're sure you don't want the function to raise exceptions.
          2. Use an 'int' return type on the function to allow an error code to be returned.
      Compiling src/gevent/libev/corecext.pyx because it changed.
      [1/1] Cythonizing src/gevent/libev/corecext.pyx
      Compiling src/gevent/_greenlet_primitives.py because it changed.
      [1/1] Cythonizing src/gevent/_greenlet_primitives.py
      Compiling src/gevent/_hub_primitives.py because it changed.
      [1/1] Cythonizing src/gevent/_hub_primitives.py
      Compiling src/gevent/_hub_local.py because it changed.
      [1/1] Cythonizing src/gevent/_hub_local.py
      Compiling src/gevent/_waiter.py because it changed.
      [1/1] Cythonizing src/gevent/_waiter.py
      warning: src/gevent/_gevent_cgreenlet.pxd:112:33: Declarations should not be declared inline.
      
      Error compiling Cython file:
      ------------------------------------------------------------
      ...
      cdef load_traceback
      cdef Waiter
      cdef wait
      cdef iwait
      cdef reraise
      cpdef GEVENT_CONFIG
            ^
      ------------------------------------------------------------
      
      src/gevent/_gevent_cgreenlet.pxd:182:6: Variables cannot be declared with 'cpdef'. Use 'cdef' instead.
      Compiling src/gevent/greenlet.py because it changed.
      [1/1] Cythonizing src/gevent/greenlet.py
      Traceback (most recent call last):
        File "/usr/lib/python3/dist-packages/pip/_vendor/pep517/in_process/_in_process.py", line 363, in <module>
          main()
        File "/usr/lib/python3/dist-packages/pip/_vendor/pep517/in_process/_in_process.py", line 345, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
        File "/usr/lib/python3/dist-packages/pip/_vendor/pep517/in_process/_in_process.py", line 130, in get_requires_for_build_wheel
          return hook(config_settings)
        File "/usr/lib/python3/dist-packages/setuptools/build_meta.py", line 162, in get_requires_for_build_wheel
          return self._get_build_requires(
        File "/usr/lib/python3/dist-packages/setuptools/build_meta.py", line 143, in _get_build_requires
          self.run_setup()
        File "/usr/lib/python3/dist-packages/setuptools/build_meta.py", line 267, in run_setup
          super(_BuildMetaLegacyBackend,
        File "/usr/lib/python3/dist-packages/setuptools/build_meta.py", line 158, in run_setup
          exec(compile(code, __file__, 'exec'), locals())
        File "setup.py", line 294, in <module>
          EXT_MODULES.append(cythonize1(mod))
        File "/tmp/pip-install-axxodj9m/gevent_188e47a78e0a4647b09609828c5fac26/_setuputils.py", line 237, in cythonize1
          new_ext = cythonize(
        File "/tmp/pip-build-env-p730dgbz/overlay/local/lib/python3.10/dist-packages/Cython/Build/Dependencies.py", line 1154, in cythonize
          cythonize_one(*args)
        File "/tmp/pip-build-env-p730dgbz/overlay/local/lib/python3.10/dist-packages/Cython/Build/Dependencies.py", line 1321, in cythonize_one
          raise CompileError(None, pyx_file)
      Cython.Compiler.Errors.CompileError: src/gevent/greenlet.py
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.

Inside requirements.txt:

eventlet==0.33.3
Flask==1.1.1
Flask-SocketIO==4.1.0
python-socketio==4.2.0
python-engineio==3.13.0
greenlet==1.0.0
gevent==21.1.2
gevent-websocket==0.10.1
attrdict
numpy
pillow
opencv-contrib-python

I'm running Ubuntu 22.04 with ROS2 Humble

Hi,

This seems to be a dependency issue, which we haven't come across before. That being said, we are happy to debug it together with you.

After searching for a similar issue, we found this issue, which states that Python 3.11 is missing certain pre-built wheels required by gevent. In case that is indeed the issue, the solution to another issue here mentions running the following command before installing gevent: apt-get update && apt-get install -y --no-install-recommends build-essential

Can you let us know your Python version? Alternatively, you could create a virtual environment with a slightly older Python version (we have tested with Python 3.8.10 and 3.9.13) to see if that helps.

Let us know how it goes. Best of luck!

Hi @Marnonel6 , seems like you're using python 3.10 and as @Tinker-Twins mentioned, that might be the issue.

I was in the same boat because I was running Devkit on 3.10.12.

Here's the workaround for this issue:

The primary reason for your error is gevent's version not supporting the newer Cpython's recynthonizing. See gevent/gevent#1899 (comment)

The workaround is to set gevent to a newer version. In my case, I followed the suggestion in gevent/gevent#1899 (comment) and changed to pip install gevent>=21.12.0.

After that, you'll encounter another problem in which there's an import error on the line from collections import Mapping from attrdict because of attrdict's deprecation in >=python3.10.

For that problem, I replaced all instances of from attrdict import AttrDict with the monkey patch here. It essentially copies attributes from collections to collections.abc.

@Tinker-Twins I tried creating a virtual environment by installing Python 3.8 that's callable by python3.8 and creating a virtualenv with it. However, the sourcing is complicated with building the package, sourcing the built package, etc. to the point where the same error persists because the python3 at my /usr/bin/env was still used in the package, which is version 3.10.12.