Python and Libraries¶
The RACECAR-MN is programmed with the Python programming language, so we will need to install the newest version of Python along with a few Python libraries.
In short, you will need to run the following commands on the terminal.
Windows and Linux:
sudo apt update sudo apt install python3.8 sudo apt install python3-pip pip3 install numpy pip3 install matplotlib pip3 install mypy pip3 install nptyping sudo apt install python3-opencv pip3 install jupyter pip3 install ipywidgets jupyter nbextension enable --py widgetsnbextension
xcode-select --install ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" brew install python3 pip3 install numpy pip3 install matplotlib pip3 install mypy pip3 install nptyping pip3 install opencv-python pip3 install jupyter pip3 install ipywidgets jupyter nbextension enable --py widgetsnbextension
Installing Python 3¶
To check if Python 3 is already installed, run
python3 --version. If it returns
Python 3.x.x, (such as
Python 3.8.3), then Python 3 is already installed and you can skip to the Installing Libraries section.
If not, follow the steps below to install Python 3 on your computer.
Windows and Linux¶
- We will install Python with APT (Advanced Package Tool), so we first need to make sure that APT is up to date. Open a terminal and run
sudo apt update. Remember that if you are using Windows, you must use a bash terminal (see Windows Only: Ubuntu on Windows), not cmd or PowerShell.
- To install Python, run the command
sudo apt install python3.8. When you are asked “Do you want to continue?”, enter
- Finally, we need to install pip, the Python package management system, which will allow us to install libraries such as NumPy and OpenCV. Run the command
sudo apt install python3-pip.
Unfortunately, Mac does not have APT, so we will need to install and use homebrew instead.
- Install XCode by running
xcode-select --installon the terminal.
- Install Homebrew by running
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)on the terminal.
- Install Python 3 by running
brew install python3.
You can find more details here.
Libraries are pieces of code written by other people which we can use in our programs. For example, the NumPy library allows us to efficiently handle large arrays, and we will use to store and process the images captured by the car.
To install a library, type the command
pip3 install <libraryname> on the terminal. You will need to install the following Python libraries:
- NumPy helps us process large arrays and matrices. Install it by entering
pip3 install numpyon the terminal.
- Matplotlib helps us display images and data. Install it by entering
pip3 install matplotlibon the terminal.
- MyPy is a static type checker which can help identify mistakes before we run our program. Install it by entering
pip3 install mypyon the terminal.
- Nptyping extends python type hints to support Numpy types. Install it by entering
pip3 install nptypingon the terminal.
OpenCV helps us process images.
- If you are using Windows or Linux, install it with
sudo apt install python3-opencv.
- If you are using Mac, install it with
pip3 install opencv-python.
Jupyter Notebook is a web application which can incrementally run pieces of code. It is ideally suited for exploration and collaboration and is heavily used in data science and CS education. We will be using Jupyter Notebooks in the exploration portions of several labs to learn how to process the different data sources on the car.
- Install Jupyter by entering
pip3 install jupyteron the terminal.
- Next, we need to install the
ipywidgetsextension, which is necessary to use the widgets in several of our notebooks. Enter
pip3 install ipywidgets.
- Finally, we need to enable the widget extension. Enter
jupyter nbextension enable --py widgetsnbextension. If you see a message that ends with
- Validating: OK, the widget extension was successfully enabled.