How to install the Cityflow simulator in Windows 11
Why am I writing this?
I am writing this “how-to” guide for the Cityflow simulator mostly because it took me a few days to make it work in Windows 11. So if anyone else finds him/herself in the same position as I was I hope this guide will shed some light.
What is Cityflow?
Cityflow is an open-source traffic simulator. Comparable to SUMO it is much faster. CityFlow can support flexible definitions for the road networks and traffic flow based on synthetic and real-world data. It also provides a user-friendly interface for reinforcement learning.
How to install Cityflow
TL;DR
You can install Cityflow to a specific python virtual environment. First of all, open your WSL2 terminal and navigate to the home directory. Steps:
# Install cpp dependencies:
sudo apt update && sudo apt install -y build-essential cmake# Clone Cityflow repo
git clone https://github.com/cityflow-project/CityFlow.git# Create a new virtual environment with python:
virtualenv -p /usr/bin/python3.x venv# activate virtual env
source venv/bin/activate# With venv activated move to Cityflow directory:
cd Cityflow# install Cityflow
pip install .# To install gym-cityflow go to home directory:
cd ..
git clone https://github.com/MaxVanDijck/gym-cityflow
# navigate to gym-cityflow directory
cd gym-cityflow
# with venv activated run
pip install -e .# Finally, you need to install gym package and the rest RL packages:
pip install gym
First things first
I assume that WSL2 is activated in your system. I have installed the Ubuntu 20.04 version on my laptop. Open a new Ubuntu terminal and navigate to your home directory. You need to install cpp dependencies:
sudo apt update && sudo apt install -y build-essential cmake
Clone Github repositories
After this step you need to clone the Cityflow project repository:
git clone https://github.com/cityflow-project/CityFlow.git
This will create a folder with the name Cityflow.
Python Virtual Environment
Move on and create a new virtual environment for python. I am a fan of the virtualenv
package but you can use whatever you want. I used python3.8.
virtualenv -p /usr/bin/python3.x venv
Activate your virtual environment and navigate to the Cityflow folder:
source venv/bin/activate
cd Cityflow
Of course, you can use Anaconda or Miniconda if you like.
Then install Cityflow package by hitting:
pip install .
Gym-cityflow
Cityflow now comes as a custom environment on openai gym package. You can move on to install this following the next steps:
cd ..
git clone https://github.com/MaxVanDijck/gym-cityflow
After that go to the gym-cityflow folder and run:
cd gym-cityflow
pip install -e .
Make sure that gym package has been installed by running:
pip install gym
And that’s it. Cityflow has been installed in your system along with gym-cityflow which lets you use RL algorithms.
Happy Reinforcement Learning Coding!