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)
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
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:
- 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.)
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.
Run the configuration scripts:
Setup.bat
GenerateProjectFiles.bat
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 if you need any help.
- 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.
- 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
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.
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:
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:
- From the root CARLA directory, navigate to \Util\ContentVersions.txt. This document contains the links to the assets for all CARLA releases.
- Extract the assets in Unreal\CarlaUE4\Content\Carla. If the path doesn’t exist, create it.
- Extract the file with a command similar to the following:
-> YOU MAY IGNORE THE ABOVE PART <-tar -xvzf <assets_file_name>.tar.gz.tar -C C:\path\to\carla\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:
- Open Windows Control Panel and go to
Advanced System Settings
or search forAdvanced System Settings
in the Windows search bar. - On the
Advanced
panel openEnvironment Variables....
- Click
New...
to create the variable. - 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:
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 the
Carla/Util/BuildTools/BuildPythonAPI.bat
(open here means edit it, but not run the .bat script) - replace all
py
inCarla/Util/BuildTools/BuildPythonAPI.bat
bypython
- replace
py -3 setup.py bdist_egg
bypython 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).
@echo off
setlocal
rem BAT script that creates the client python api of LibCarla (carla.org).
rem Run it through a cmd with the x64 Visual C++ Toolset enabled.
set LOCAL_PATH=%~dp0
set "FILE_N=-[%~n0]:"
rem Print batch params (debug purpose)
echo %FILE_N% [Batch params]: %*
rem ============================================================================
rem -- Parse arguments ---------------------------------------------------------
rem ============================================================================
set DOC_STRING=Build and package CARLA Python API.
set "USAGE_STRING=Usage: %FILE_N% [-h^|--help] [--rebuild] [--clean]"
set REMOVE_INTERMEDIATE=false
set BUILD_FOR_PYTHON2=false
set BUILD_FOR_PYTHON3=false
:arg-parse
if not "%1"=="" (
if "%1"=="--rebuild" (
set REMOVE_INTERMEDIATE=true
rem We don't provide support for py2 right now
set BUILD_FOR_PYTHON2=false
set BUILD_FOR_PYTHON3=true
)
if "%1"=="--py2" (
set BUILD_FOR_PYTHON2=true
)
if "%1"=="--py3" (
set BUILD_FOR_PYTHON3=true
)
if "%1"=="--clean" (
set REMOVE_INTERMEDIATE=true
)
if "%1"=="-h" (
echo %DOC_STRING%
echo %USAGE_STRING%
GOTO :eof
)
if "%1"=="--help" (
echo %DOC_STRING%
echo %USAGE_STRING%
GOTO :eof
)
shift
goto :arg-parse
)
set PYTHON_LIB_PATH=%ROOT_PATH:/=\%PythonAPI\carla\
if %REMOVE_INTERMEDIATE% == false (
if %BUILD_FOR_PYTHON3% == false (
if %BUILD_FOR_PYTHON2% == false (
echo Nothing selected to be done.
goto :eof
)
)
)
if %REMOVE_INTERMEDIATE% == true (
rem Remove directories
for %%G in (
"%PYTHON_LIB_PATH%build",
"%PYTHON_LIB_PATH%dist",
"%PYTHON_LIB_PATH%source\carla.egg-info"
) do (
if exist %%G (
echo %FILE_N% Cleaning %%G
rmdir /s/q %%G
)
)
if %BUILD_FOR_PYTHON3% == false (
if %BUILD_FOR_PYTHON2% == false (
goto good_exit
)
)
)
cd "%PYTHON_LIB_PATH%"
rem if exist "%PYTHON_LIB_PATH%dist" goto already_installed
rem ============================================================================
rem -- Check for python ------------------------------------------------------------
rem ============================================================================
where python 1>nul
if %errorlevel% neq 0 goto error_py
rem Build for Python 2
rem
if %BUILD_FOR_PYTHON2%==true (
goto py2_not_supported
)
rem Build for Python 2
rem
if %BUILD_FOR_PYTHON3%==true (
echo Building Python API for Python 3.
python setup.py bdist_egg
if %errorlevel% neq 0 goto error_build_egg
)
goto success
rem ============================================================================
rem -- Messages and Errors -----------------------------------------------------
rem ============================================================================
:success
echo.
if %BUILD_FOR_PYTHON3%==true echo %FILE_N% Carla lib for python has been successfully installed in "%PYTHON_LIB_PATH%dist"!
goto good_exit
:already_installed
echo.
echo %FILE_N% [ERROR] Already installed in "%PYTHON_LIB_PATH%dist"
goto good_exit
:py2_not_supported
echo.
echo %FILE_N% [ERROR] Python 2 is not currently suported in Windows.
goto bad_exit
:error_py
echo.
echo %FILE_N% [ERROR] An error ocurred while executing the py.
echo %FILE_N% [ERROR] Possible causes:
echo %FILE_N% [ERROR] - Make sure "py" is installed.
echo %FILE_N% [ERROR] - python = python launcher. This utility is bundled with Python installation but not installed by default.
echo %FILE_N% [ERROR] - Make sure it is available on your Windows "py".
goto bad_exit
:error_build_egg
echo.
echo %FILE_N% [ERROR] An error occurred while building the egg file.
goto bad_exit
:good_exit
endlocal
exit /b 0
:bad_exit
endlocal
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:
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:
# Terminal A
cd PythonAPI\examples
pip3 install -r requirements.txt
python3 generate_traffic.py
# Terminal B
cd PythonAPI\examples
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
- 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”
- https://mcci.com/support/guides/how-to-change-the-windows-pagefile-size/ Follow the steps to change the Windows pagefile larger.
Build CARLA part
- Issues like “xerces-c_3.lib (ICUTransService.obj): error LNK 2001: unresolved external symbol u_strlen_58”
- please make sure you replaced all
py
inCarla/Util/BuildTools/BuildPythonAPI.bat
bypython