carla-simulator / carla

Open-source simulator for autonomous driving research.
http://carla.org
MIT License
11.42k stars 3.7k forks source link

Making Carla build with Python 3.10 #5538

Open grimmmbo opened 2 years ago

grimmmbo commented 2 years ago

Hi all,

we want to use the Carla ROS Bridge with the recently released version of ROS2, Humble. However, Humble is targeting Ubuntu 22, which is delivered with Python 3.10 as default. Thus, it would be great if the compiling process of Carla would support using Python 3.10 for building the PythonAPI. If anyone has the same struggle, the following steps led to a successful build of PythonAPI, make launch and make package to get a new release of Carla 0.9.13 with python 3.10 support:

Hopefully, somebody can test it and use that for a PR maybe :)

dayaguec commented 2 years ago

Hi everyone,

We are in the same circumstances wanting to use Carla 0.9.13 (latest release right now) with Ubuntu 22 and ROS 2 Humble. I can confirm that this workaround led to a successful compilation of Carla PythonAPI against Python 3.10. However, testing the generated egg file for my platform it seems that it is not always working. I tested this in two different set ups, Ubuntu 18 and Ubuntu 20, following the instructions posted here and using Python 3.10.4 installed from source and Python 3.10.5 installed from a deadsnakes PPA respectively. In both situations the egg file seems to work properly, using in Ubuntu 22 the precompile 0.9.13 release package of Carla.

However, when testing the generate_traffic.py script to generate vehicles and walkers in Carla world, the server crashes and the client produces a segmentation fault with no error or warning in the terminal only a report of Ubuntu with a “Python 3.10 crashed with a SIGSEGV (reading NULL VMA) in PyType_GenericAlloc()”. I debugged that particular script and found that the function get_random_location_from_navigation(), which retrieves a random location to be used as a destination using the go_to_location() method in carla.WalkerAIController is causing the segmentation fault. This means that other functions similar to this one may be affected in the same way having this setup.

Maybe this error is related with the changes applied to boost before compiling or maybe it is just a coherent error taking into consideration that we are using the client with a set up different from the one used by the original developers. I was also able to compile with both, boots 1.75 and the original boost 1.72 (it was not necessary to comment Gtests) and in both cases this error still appears. After looking at the code I realized that this function is the only one affected by the CALL_RETURNING_OPTIONAL_WITHOUT_GIL in libcarla.cpp, maybe this is related.

I do not know if I am missing something but I hope this helps in a future workaround or maybe a new release for those using Carla in new Ubuntu versions.

EDIT: Ok, after looking at this error I came up with this issue #5658 which states that for Python 3.9 and Python 3.10 CALL_RETURNING_OPTIONAL_WITHOUT_GIL must be changed with CALL_RETURNING_OPTIONAL. After that change in World.cpp it seems to work properly.

WangwangZhu commented 1 year ago

Hi, I am trying to compile the carla in Ubuntu 22.04 with ROS2 humble, I am stacking by the clang version, I want to ask which version of clang you used to while running " make PythonAPI"?, Thanks a lot.

dayaguec commented 1 year ago

Hi, I am trying to compile the carla in Ubuntu 22.04 with ROS2 humble, I am stacking by the clang version, I want to ask which version of clang you used to while running " make PythonAPI"?, Thanks a lot.

Taking into account my experience with this matter, I do not think Carla can be build in Ubuntu 22.04 right now since the compilation tool chain contains a lot of dependencies and incompatibilities for this Ubuntu distribution. Besides, Carla developers stated in the documentation that it is not supported for the time being. Having that said, what I did in my case was building Carla in Ubuntu 20.04 and compile the Python API against Python 3.10 to produce an eggfile for the binary version (since the binary version works on Ubuntu 22.04). Then you can use Carla with Python 3.10 and ROS 2 Humble that uses Python 3.10.

WangwangZhu commented 1 year ago

Hi, I am trying to compile the carla in Ubuntu 22.04 with ROS2 humble, I am stacking by the clang version, I want to ask which version of clang you used to while running " make PythonAPI"?, Thanks a lot.

Taking into account my experience with this matter, I do not think Carla can be build in Ubuntu 22.04 right now since the compilation tool chain contains a lot of dependencies and incompatibilities for this Ubuntu distribution. Besides, Carla developers stated in the documentation that it is not supported for the time being. Having that said, what I did in my case was building Carla in Ubuntu 20.04 and compile the Python API against Python 3.10 to produce an eggfile for the binary version (since the binary version works on Ubuntu 22.04). Then you can use Carla with Python 3.10 and ROS 2 Humble that uses Python 3.10.

Thanks for your suggestion~ I have followed your suggestion, and compiled the custommed map in Ubuntu 20.04 and copy the package to Ununtu 22.04. Carla worked well now. While I am compileingthe PythonAPI, the command "make PythonAPI" failed, the ERROR showed that I using the wrong clang version. I want to ask what's the version you used while building the PythonAPI with python 3.10

dayaguec commented 1 year ago

Hi, I am trying to compile the carla in Ubuntu 22.04 with ROS2 humble, I am stacking by the clang version, I want to ask which version of clang you used to while running " make PythonAPI"?, Thanks a lot.

Taking into account my experience with this matter, I do not think Carla can be build in Ubuntu 22.04 right now since the compilation tool chain contains a lot of dependencies and incompatibilities for this Ubuntu distribution. Besides, Carla developers stated in the documentation that it is not supported for the time being. Having that said, what I did in my case was building Carla in Ubuntu 20.04 and compile the Python API against Python 3.10 to produce an eggfile for the binary version (since the binary version works on Ubuntu 22.04). Then you can use Carla with Python 3.10 and ROS 2 Humble that uses Python 3.10.

Thanks for your suggestion~ I have followed your suggestion, and compiled the custommed map in Ubuntu 20.04 and copy the package to Ununtu 22.04. Carla worked well now. While I am compileingthe PythonAPI, the command "make PythonAPI" failed, the ERROR showed that I using the wrong clang version. I want to ask what's the version you used while building the PythonAPI with python 3.10

Oh, ok. Following the build instructions for linux, Ubuntu 20.04 I used: clang-10 lld-10 and g++-7. Remember to update the alternatives when building:

sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/lib/llvm-10/bin/clang++ 180 && sudo update-alternatives --install /usr/bin/clang clang /usr/lib/llvm-10/bin/clang 180

WangwangZhu commented 1 year ago

Hi, I am trying to compile the carla in Ubuntu 22.04 with ROS2 humble, I am stacking by the clang version, I want to ask which version of clang you used to while running " make PythonAPI"?, Thanks a lot.

Taking into account my experience with this matter, I do not think Carla can be build in Ubuntu 22.04 right now since the compilation tool chain contains a lot of dependencies and incompatibilities for this Ubuntu distribution. Besides, Carla developers stated in the documentation that it is not supported for the time being. Having that said, what I did in my case was building Carla in Ubuntu 20.04 and compile the Python API against Python 3.10 to produce an eggfile for the binary version (since the binary version works on Ubuntu 22.04). Then you can use Carla with Python 3.10 and ROS 2 Humble that uses Python 3.10.

Thanks for your suggestion~ I have followed your suggestion, and compiled the custommed map in Ubuntu 20.04 and copy the package to Ununtu 22.04. Carla worked well now. While I am compileingthe PythonAPI, the command "make PythonAPI" failed, the ERROR showed that I using the wrong clang version. I want to ask what's the version you used while building the PythonAPI with python 3.10

Oh, ok. Following the build instructions for linux, Ubuntu 20.04 I used: clang-10 lld-10 and g++-7. Remember to update the alternatives when building:

sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/lib/llvm-10/bin/clang++ 180 && sudo update-alternatives --install /usr/bin/clang clang /usr/lib/llvm-10/bin/clang 180

While installing clang-10, did you encouter this problems: E: Package 'clang-10' has no installation candidate E: Unable to locate package lld-10 E: Package 'g++-7' has no installation candidate E: Package 'python' has no installation candidate E: Package 'python-dev' has no installation candidate

dayaguec commented 1 year ago

Hi, I am trying to compile the carla in Ubuntu 22.04 with ROS2 humble, I am stacking by the clang version, I want to ask which version of clang you used to while running " make PythonAPI"?, Thanks a lot.

Taking into account my experience with this matter, I do not think Carla can be build in Ubuntu 22.04 right now since the compilation tool chain contains a lot of dependencies and incompatibilities for this Ubuntu distribution. Besides, Carla developers stated in the documentation that it is not supported for the time being. Having that said, what I did in my case was building Carla in Ubuntu 20.04 and compile the Python API against Python 3.10 to produce an eggfile for the binary version (since the binary version works on Ubuntu 22.04). Then you can use Carla with Python 3.10 and ROS 2 Humble that uses Python 3.10.

Thanks for your suggestion~ I have followed your suggestion, and compiled the custommed map in Ubuntu 20.04 and copy the package to Ununtu 22.04. Carla worked well now. While I am compileingthe PythonAPI, the command "make PythonAPI" failed, the ERROR showed that I using the wrong clang version. I want to ask what's the version you used while building the PythonAPI with python 3.10

Oh, ok. Following the build instructions for linux, Ubuntu 20.04 I used: clang-10 lld-10 and g++-7. Remember to update the alternatives when building: sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/lib/llvm-10/bin/clang++ 180 && sudo update-alternatives --install /usr/bin/clang clang /usr/lib/llvm-10/bin/clang 180

While installing clang-10, did you encouter this problems: E: Package 'clang-10' has no installation candidate E: Unable to locate package lld-10 E: Package 'g++-7' has no installation candidate E: Package 'python' has no installation candidate E: Package 'python-dev' has no installation candidate

Add apt sources: sudo apt-add-repository "deb http://apt.llvm.org/focal/ llvm-toolchain-focal main"

Follow the build instructions from the documentation.

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Andrey9491 commented 1 year ago

https://github.com/gezp/carla_ros

roshambo919 commented 1 year ago

We've incorporated these updates in our fork: https://github.com/avstack-lab/carla/tree/build_0.9.13_py310_ubuntu22

See how we're using this with other python 3.10 libraries here: https://github.com/avstack-lab/carla-sandbox

trand2k commented 1 year ago

https://github.com/gezp/carla_ros

good job