# Driving Simulator Reloaded - CARLA Installation **CARLA Documentation - Windows build** This guide details how to build CARLA from source on Windows **directly customized for 2022 Driving Simulator Reloaded**. There are two parts. Part one details system requirements and installations of required software, and part two details how to actually build and run CARLA. The build process is long (4 hours or more) and involves several kinds of software. It is highly recommended to read through the guide fully before starting. If you come across errors or difficulties then have a look at the F.A.Q. page which offers solutions for the most common complications. Alternatively, ask me (Melih#0956 on Discord) or use the CARLA forum to post any queries you may have. Note: This guide was written for the 2022 University of Bremen semester project "Driving Simulator Reloaded", so it might be outdated for future use. Please refrain from contacting me about this guide after the project ends. I am however still open to other questions. --- 1. [Part One: Prerequisites](https://hackmd.io/UMpMF2WGTja4HeYhpefzlw?both#Part-One-Prerequisites) 1.1 [System requirements](https://hackmd.io/UMpMF2WGTja4HeYhpefzlw?both#System-requirements) 1.2 [Software requirements](https://hackmd.io/UMpMF2WGTja4HeYhpefzlw?both#Software-requirements) 1.2.1 [Minor installations](https://hackmd.io/UMpMF2WGTja4HeYhpefzlw?both#Minor-installations) 1.2.2 [Python dependencies](https://hackmd.io/UMpMF2WGTja4HeYhpefzlw?both#Python-dependencies) 1.2.3 [Major installations](https://hackmd.io/UMpMF2WGTja4HeYhpefzlw?both#Major-installations) 1.2.3.1 [Visual Studio 2019](https://hackmd.io/UMpMF2WGTja4HeYhpefzlw?both#Visual-Studio-2019) 1.2.3.2 [Unreal Engine](https://hackmd.io/UMpMF2WGTja4HeYhpefzlw?both#Unreal-Engine) 2. [Part Two: Build CARLA](https://hackmd.io/UMpMF2WGTja4HeYhpefzlw?both#Part-Two-Build-CARLA) 2.1 [Clone the CARLA repository](https://hackmd.io/UMpMF2WGTja4HeYhpefzlw?both#Clone-the-CARLA-repository) 2.2 [Get assets](https://hackmd.io/UMpMF2WGTja4HeYhpefzlw?both#Get-assets) 2.3 [Set Unreal Engine environment variable](https://hackmd.io/UMpMF2WGTja4HeYhpefzlw?both#Set-Unreal-Engine-environment-variable) 2.4 [Build CARLA](https://hackmd.io/UMpMF2WGTja4HeYhpefzlw?both#Build-CARLA) **Part One: Prerequisites** -- In this section you will find details of system requirements, minor and major software installations and Python dependencies that are required before you can begin to build CARLA. --- **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. * **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. --- **Software requirements** -- --- **Minor installations** -- * **[CMake](https://cmake.org/download/)** generates standard build files from simple configuration files. * **[Git](https://git-scm.com/downloads)** is a version control system to manage CARLA repositories. * **[Make](http://gnuwin32.sourceforge.net/packages/make.htm)** 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`. * **[7Zip](https://www.7-zip.org/)** is a file compression software. 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](https://www.python.org/downloads/)** is the main scripting language in CARLA. Having a x32 version installed may cause conflict, so it is highly advisable to have it uninstalled. **Make sure to install version 3.7.x, I personally installed 3.7.9**. 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: Default bin directories: * CMake: ...\CMake\bin * Git: * Make: ...\GnuWin32\bin * 7Zip: ...\7Zip * Python: C:\Users\YourUsername\AppData\Local\Programs\Python\Python37\ **AND** C:\Users\YourUsername\AppData\Local\Programs\Python\Python37\Scripts\ (add both to path) --- **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 in your default terminal: ``` pip3 -V ``` If you need to upgrade: ``` pip3 install --upgrade pip ``` You must install the following Python dependencies: ``` pip3 install --user setuptools pip3 install --user wheel pip install carla ``` --- **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: * Windows 8.1 SDK. 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](https://www.unrealengine.com/en-US/ue-on-github) before going any further. To 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**: `git clone --depth 1 -b carla https://github.com/CarlaUnreal/UnrealEngine.git` Note: Keep the Unreal Engine folder as close as C:\\ as you can because if the path exceeds a certain length then Setup.bat will return errors in step 3. 2. **Run the configuration scripts (not in terminal, in the Unreal Engine folder):** `Setup.bat` and `GenerateProjectFiles.bat` 3. **Compile the modified engine:** Open the UE4.sln file inside the source folder with Visual Studio 2019. In the build bar ensure that you have selected 'Development Editor', 'Win64' and 'UnrealBuildTool' options. Check [this guide](https://docs.unrealengine.com/5.0/en-US/setting-up-your-development-environment-for-cplusplus-in-unreal-engine/BuildingUnrealEngine) if you need any help. In the solution explorer, right-click UE4 and select Build. 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.` --- A lot has happened so far, so it is advisable to restart your machine at this point. --- **Part Two: Build CARLA** -- **Clone the CARLA repository** -- Clone the official repository of the project using this command: ``` git clone https://gitlab.informatik.uni-bremen.de/drivingsimulatorreloaded/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: ``` Update.bat ``` The assets will be downloaded and extracted to the appropriate location if have 7zip installed. This can take up to a few hours depending on your internet connection. If you do not have 7Zip installed, you will need to manually extract the file contents to ``` Unreal\CarlaUE4\Content\Carla ``` **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 Settings* or search for *Advanced System Settings* in the Windows search bar. 1. On the *Advanced* panel open *Environment Variables....* 1. Click *New...* to create the variable. 1. 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 in this section should be run in the root CARLA folder. All commands in this section should be executed via the **x64 Native Tools Command Prompt for VS 2019**. Open this by clicking the *Windows* key and searching for *x64*. There are two parts to the build process for CARLA, compiling the client and compiling the server. **1. Compile the Python API client:** 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: ``` 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 ``` This can take a long time, depending on your computer/laptop. 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 x64-terminal for each script and run the following commands to spawn some life into the town and create a weather cycle: ``` # Terminal A cd PythonAPI\examples pip3 install -r requirements.txt python generate_traffic.py # Terminal B cd PythonAPI\examples python dynamic_weather.py ``` If the simulation is running at very low FPS, go to *Edit -> Editor Preferences -> Performance* in the Unreal Engine editor and disable *Use less CPU when in background*.