Part 0. Pre-prerequisites

ATTENTION. Buidling carla in Windows is extremely time consuming. It will takes about 4 hours to build every thing in your windows. Be patient, be wise! DO exactly follow the steps in what I list below. If u meet any issue, plz re-read the docoment to check if you follow the steps. If the issue still cannot be fixed, plz contact “ysong279@wisc.edu”. Also, you might get an instant reply by using wechat: Angry_Gingerbread, feel free to talk to me if necessarry. I will try to reply to you asap. The document list below mainly follow the structure of the official document. The document you are reading now is a edited version. You may check the original one if you want. https://carla.readthedocs.io/en/latest/build_windows/. I also posted a FAQ part at the end of this page, check it first when you have any issue.


Part 1. Prerequisites

System requirements

  • x64 system. The simulator should run in any 64 bits Windows system.
  • 165 GB disk space. CARLA itself will take around 32 GB and the related major software installations (including Unreal Engine) will take around 133 GB. This one is important, plz make sure u shared enough space for the carla.
  • An adequate GPU. CARLA aims for realistic simulations, so the server needs at least a 6 GB GPU although 8 GB is recommended. A dedicated GPU is highly recommended for machine learning.
  • Two TCP ports and good internet connection. 2000 and 2001 by default. Make sure that these ports are not blocked by firewalls or any other applications. This is normally no need to look at.

    Software requirements

    In this part, you will need to install three parts softwares: minor installation, python dependencies installation, major installations. Please DO follow the instruction step by step.

    Minor installation

    IMPORTANT: Be sure that the above programs are added to the environment path. Remember that the path added should correspond to the progam’s bin directory. Some of the program listed below dont need you to add to the envrionment path manually because it has option to do that during the installation step. If you dont know how to add the programs to the environment path, plz google like: how to add CMake(an example) to environment path in windows.

  • CMake generates standard build files from simple configuration files.

  • Git is a version control system to manage CARLA repositories.
  • Make generates the executables. It is necessary to use Make version 3.81, otherwise the build may fail. If you have multiple versions of Make installed, check that you are using version 3.81 in your PATH when building CARLA. You can check your default version of Make by running make —version.
  • (optional) 7Zip is a file compression software. If you have other compression software, you may skip this step. This is required for automatic decompression of asset files and prevents errors during build time due to large files being extracted incorrectly or partially.
  • Python3 x64 is the main scripting language in CARLA. CARLA can only support Python 3.7 version. Having a x32 version installed may cause conflict, so it is highly advisable to have it uninstalled. I personally stronly recomend you uninstall all the python versions on your computer, and then install python 3.7 (also do remember to add it into environment PATH, but it is usually dont need you to that mannually by defaut). If you are using the Anaconda to manage the python version, do remember to set the base python as python 3.7X version OR activate your environment your python 3.7 environments, and run all scripts listed below in that environment. HOWEVER, I didn’t try that, so I cannot promise you will not face issues in the following steps.

Python dependencies

Starting with CARLA 0.9.12, users have the option to install the CARLA Python API using pip3. Version 20.3 or higher is required. To check if you have a suitable version, run the following command:
(ATTENTION: if you are using the Anaconda to manage python versions, do remeber to activate it)

  1. pip3 -V

If you need to upgrade:

  1. pip3 install --upgrade pip

You must install the following Python dependencies:

  1. pip3 install --user setuptools pip3 install --user wheel

Major installations

Visual Studio 2019

Get the 2019 version of Visual Studio from here. Choose Community for the free version. Use the Visual Studio Installer to install three additional elements(Besides Windows 8.1 SDK, you need install this manually):

  • Windows 8.1 SDK. NOTICE: Windows 8.1 SDK is now removed from the Visual Studio 2019. You now need to install it by yourself. Click this link to install. Select it in the ~~_Installation details_ section on the right or go to the _Indivdual Components_ tab and look under the _SDKs, libraries, and frameworks_ heading.~~
  • x64 Visual C++ Toolset. In the Workloads section, choose Desktop development with C++. This will enable a x64 command prompt that will be used for the build. Check that it has been installed correctly by pressing the Windows button and searching for x64. Be careful not to open a x86_x64 prompt.
  • .NET framework 4.6.2. In the Workloads section, choose .NET desktop development and then in the Installation details panel on the right, select .NET Framework 4.6.2 development tools. This is required to build Unreal Engine.

    IMPORTANT Other Visual Studio versions may cause conflict. Even if these have been uninstalled, some registers may persist. To completely clean Visual Studio from the computer, go to Program Files (x86)\Microsoft Visual Studio\Installer\resources\app\layout and run .\InstallCleanup.exe -full

Unreal Engine

Starting with version 0.9.12, CARLA uses a modified fork of Unreal Engine 4.26. This fork contains patches specific to CARLA.
Be aware that to download this fork of Unreal Engine, you need to have a GitHub account linked to Unreal Engine’s account. If you don’t have this set up, please follow this guide before going any further.

No Build the modified version of Unreal Engine:

  1. In a terminal, navigate to the location you want to save Unreal Engine and clone the carla branch:

(If you have any issue like, “no permission to access”. please make sure you didn’t forget to link your github account to UE4 account.)

  1. git clone --depth 1 -b carla https://github.com/CarlaUnreal/UnrealEngine.git .

IMPORTANT Keep the Unreal Engine folder as close as C:\ (this doese mean you have to put everything into C drive.) as you can because if the path exceeds a certain length then Setup.bat will return errors in step 3.

  1. Run the configuration scripts:

    1. Setup.bat
    2. GenerateProjectFiles.bat
  2. Compile the modified engine:

    1. Open the UE4.sln file inside the source folder with Visual Studio 2019.
    2. In the build bar ensure that you have selected ‘Development Editor’, ‘Win64’ and ‘UnrealBuildTool’ options. Check this guide if you need any help.
    3. In the solution explorer, right-click UE4 and select Build. Again, check FAQ part at the end of this document if you have any issue.
  3. Once the solution is compiled you can open the engine to check that everything was installed correctly by launching the executable Engine\Binaries\Win64\UE4Editor.exe.

    IMPORTANT If the installation was successful, this should be recognised by Unreal Engine’s version selector. You can check this by right-clicking on any .uproject file and selecting Switch Unreal Engine version. You should see a pop-up showing Source Build at PATH where PATH is the installation path that you have chosen. If you can not see this selector or the Generate Visual Studio project files when you right-click on .uproject files, something went wrong with the Unreal Engine installation and you will likely need to reinstall it correctly.


Intermission

image.png
You are almost done, but not yet! The installation above you have done may not take too much time, you should meet very few issues. BUT be careful, the following steps are more important and time-consuming. BTW, a lot has happened so far. It is highly advisable to restart the computer before continuing.


Part 2. Build CARLA

Clone the CARLA repository

Change the directory to the folder you want to install the carla in the cmd prompt, then using the following code to access the CARLA repository.

  1. git clone https://github.com/carla-simulator/carla

Get assets

Download the latest assets to work with the current version of CARLA by running the following command in the CARLA root folder:

  1. Update.bat

The assets will be downloaded and extracted to the appropriate location if have 7zip installed. If you do not have this software installed, you will need to manually extract the file contents to Unreal\CarlaUE4\Content\Carla.

-> YOU MAY IGNORE THE FOLLOWING PART -<
By default, you dont need to do the following step, but if you want to download the assets for a specific version of CARLA:

  1. From the root CARLA directory, navigate to \Util\ContentVersions.txt. This document contains the links to the assets for all CARLA releases.
  2. Extract the assets in Unreal\CarlaUE4\Content\Carla. If the path doesn’t exist, create it.
  3. Extract the file with a command similar to the following:
    1. tar -xvzf <assets_file_name>.tar.gz.tar -C C:\path\to\carla\Unreal\CarlaUE4\Content\Carla
    -> YOU MAY IGNORE THE ABOVE PART <-

Set Unreal Engine environment variable

It is necessary to set an environment variable so that CARLA can find the Unreal Engine installation folder. This allows users to choose which specific version of Unreal Engine is to be used. If no environment variable is specified, then CARLA will search for Unreal Engine in the windows registry and use the first version it finds there.
To set the environment variable:

  1. Open Windows Control Panel and go to Advanced System Settingsor search for Advanced System Settings in the Windows search bar.
  2. On the Advancedpanel open Environment Variables....
  3. Click New...to create the variable.
  4. Name the variable UE4_ROOT and choose the path to the installation folder of the desired Unreal Engine installation.

Build CARLA

This section outlines the commands to build CARLA.

  • All commands should be run in the root CARLA folder.
  • Commands should be executed via the x64 Native Tools Command Prompt for VS 2019. Open this by clicking the Windows key and searching for x64. It should look like this one:

image.png

There are two parts to the build process for CARLA, compiling the client and compiling the server.

1. Compile the Python API client:

Before we compile the Python API, there are some work to do:

The basic idea is:

  • Use an editor to open theCarla/Util/BuildTools/BuildPythonAPI.bat(open here means edit it, but not run the .bat script)
  • replace all py in Carla/Util/BuildTools/BuildPythonAPI.bat by python
  • replace py -3 setup.py bdist_egg by python setup.py bdist_egg

I know it might be confusing, so I posted an edited version as following, you can just replace the original file (version 0.9.12).

  1. @echo off
  2. setlocal
  3. rem BAT script that creates the client python api of LibCarla (carla.org).
  4. rem Run it through a cmd with the x64 Visual C++ Toolset enabled.
  5. set LOCAL_PATH=%~dp0
  6. set "FILE_N=-[%~n0]:"
  7. rem Print batch params (debug purpose)
  8. echo %FILE_N% [Batch params]: %*
  9. rem ============================================================================
  10. rem -- Parse arguments ---------------------------------------------------------
  11. rem ============================================================================
  12. set DOC_STRING=Build and package CARLA Python API.
  13. set "USAGE_STRING=Usage: %FILE_N% [-h^|--help] [--rebuild] [--clean]"
  14. set REMOVE_INTERMEDIATE=false
  15. set BUILD_FOR_PYTHON2=false
  16. set BUILD_FOR_PYTHON3=false
  17. :arg-parse
  18. if not "%1"=="" (
  19. if "%1"=="--rebuild" (
  20. set REMOVE_INTERMEDIATE=true
  21. rem We don't provide support for py2 right now
  22. set BUILD_FOR_PYTHON2=false
  23. set BUILD_FOR_PYTHON3=true
  24. )
  25. if "%1"=="--py2" (
  26. set BUILD_FOR_PYTHON2=true
  27. )
  28. if "%1"=="--py3" (
  29. set BUILD_FOR_PYTHON3=true
  30. )
  31. if "%1"=="--clean" (
  32. set REMOVE_INTERMEDIATE=true
  33. )
  34. if "%1"=="-h" (
  35. echo %DOC_STRING%
  36. echo %USAGE_STRING%
  37. GOTO :eof
  38. )
  39. if "%1"=="--help" (
  40. echo %DOC_STRING%
  41. echo %USAGE_STRING%
  42. GOTO :eof
  43. )
  44. shift
  45. goto :arg-parse
  46. )
  47. set PYTHON_LIB_PATH=%ROOT_PATH:/=\%PythonAPI\carla\
  48. if %REMOVE_INTERMEDIATE% == false (
  49. if %BUILD_FOR_PYTHON3% == false (
  50. if %BUILD_FOR_PYTHON2% == false (
  51. echo Nothing selected to be done.
  52. goto :eof
  53. )
  54. )
  55. )
  56. if %REMOVE_INTERMEDIATE% == true (
  57. rem Remove directories
  58. for %%G in (
  59. "%PYTHON_LIB_PATH%build",
  60. "%PYTHON_LIB_PATH%dist",
  61. "%PYTHON_LIB_PATH%source\carla.egg-info"
  62. ) do (
  63. if exist %%G (
  64. echo %FILE_N% Cleaning %%G
  65. rmdir /s/q %%G
  66. )
  67. )
  68. if %BUILD_FOR_PYTHON3% == false (
  69. if %BUILD_FOR_PYTHON2% == false (
  70. goto good_exit
  71. )
  72. )
  73. )
  74. cd "%PYTHON_LIB_PATH%"
  75. rem if exist "%PYTHON_LIB_PATH%dist" goto already_installed
  76. rem ============================================================================
  77. rem -- Check for python ------------------------------------------------------------
  78. rem ============================================================================
  79. where python 1>nul
  80. if %errorlevel% neq 0 goto error_py
  81. rem Build for Python 2
  82. rem
  83. if %BUILD_FOR_PYTHON2%==true (
  84. goto py2_not_supported
  85. )
  86. rem Build for Python 2
  87. rem
  88. if %BUILD_FOR_PYTHON3%==true (
  89. echo Building Python API for Python 3.
  90. python setup.py bdist_egg
  91. if %errorlevel% neq 0 goto error_build_egg
  92. )
  93. goto success
  94. rem ============================================================================
  95. rem -- Messages and Errors -----------------------------------------------------
  96. rem ============================================================================
  97. :success
  98. echo.
  99. if %BUILD_FOR_PYTHON3%==true echo %FILE_N% Carla lib for python has been successfully installed in "%PYTHON_LIB_PATH%dist"!
  100. goto good_exit
  101. :already_installed
  102. echo.
  103. echo %FILE_N% [ERROR] Already installed in "%PYTHON_LIB_PATH%dist"
  104. goto good_exit
  105. :py2_not_supported
  106. echo.
  107. echo %FILE_N% [ERROR] Python 2 is not currently suported in Windows.
  108. goto bad_exit
  109. :error_py
  110. echo.
  111. echo %FILE_N% [ERROR] An error ocurred while executing the py.
  112. echo %FILE_N% [ERROR] Possible causes:
  113. echo %FILE_N% [ERROR] - Make sure "py" is installed.
  114. echo %FILE_N% [ERROR] - python = python launcher. This utility is bundled with Python installation but not installed by default.
  115. echo %FILE_N% [ERROR] - Make sure it is available on your Windows "py".
  116. goto bad_exit
  117. :error_build_egg
  118. echo.
  119. echo %FILE_N% [ERROR] An error occurred while building the egg file.
  120. goto bad_exit
  121. :good_exit
  122. endlocal
  123. exit /b 0
  124. :bad_exit
  125. endlocal
  126. exit /b %errorlevel%

Now we compile the Python API,

The Python API client grants control over the simulation. Compilation of the Python API client is required the first time you build CARLA and again after you perform any updates. After the client is compiled, you will be able to run scripts to interact with the simulation.
The following command compiles the Python API client:

  1. make PythonAPI

2. Compile the server:

The following command compiles and launches Unreal Engine. Run this command each time you want to launch the server or use the Unreal Engine editor:
make launch
The project may ask to build other instances such as UE4Editor-Carla.dll the first time. Agree in order to open the project. During the first launch, the editor may show warnings regarding shaders and mesh distance fields. These take some time to be loaded and the map will not show properly until then.

3. Start the simulation:

Press Play to start the server simulation. The camera can be moved with WASD keys and rotated by clicking the scene while moving the mouse around.
Test the simulator using the example scripts inside PythonAPI\examples. With the simulator running, open a new terminal for each script and run the following commands to spawn some life into the town and create a weather cycle:

  1. # Terminal A
  2. cd PythonAPI\examples
  3. pip3 install -r requirements.txt
  4. python3 generate_traffic.py
  5. # Terminal B
  6. cd PythonAPI\examples
  7. python3 dynamic_weather.py

Important If the simulation is running at a very low FPS rate, go to Edit -> Editor preferences -> Performance in the Unreal Engine editor and disable Use less CPU when in background.


—- THIS IS THE END OF BUILDING CARLA ON WINDOWS —-


FAQ

Unreal Engine part

  1. When in the compile unreal engine step, issues like “the paging file is too small for this operation to complete |failed to create virtual memory for pch”
  1. Issues like “xerces-c_3.lib (ICUTransService.obj): error LNK 2001: unresolved external symbol u_strlen_58”
  • please make sure you replaced all py in Carla/Util/BuildTools/BuildPythonAPI.bat by python

Others