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 --upgrade pip
pip3 install numpy
pip3 install matplotlib
pip3 install mypy
pip3 install nptyping
pip3 install opencv-contrib-python
pip3 install jupyter
pip3 install ipywidgets
jupyter nbextension enable --py widgetsnbextension
Mac:
xcode-select --install
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew install python3
pip3 install --upgrade pip
pip3 install numpy
pip3 install matplotlib
pip3 install mypy
pip3 install nptyping
pip3 install opencv-contrib-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?”, enterY
for yes.
- 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
.
Mac¶
Unfortunately, Mac does not have APT, so we will need to install and use homebrew instead.
- Install XCode by running
xcode-select --install
on 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.
Installing Libraries¶
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.
Before using pip, you should always update it to the newest version by entering pip3 install --upgrade pip
on the terminal.
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 numpy
on the terminal. - Matplotlib helps us display images and data. Install it by entering
pip3 install matplotlib
on the terminal. - MyPy is a static type checker which can help identify mistakes before we run our program. Install it by entering
pip3 install mypy
on the terminal. - Nptyping extends python type hints to support Numpy types. Install it by entering
pip3 install nptyping
on the terminal. - OpenCV helps us process images. Install it by entering
pip3 install opencv-contrib-python
on the terminal.
You can view all of the installed libraries by entering pip3 list
on the terminal. If you need to uninstall a library, enter pip3 uninstall package-name
, such as pip3 uninstall numpy`.
Installing Jupyter¶
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 jupyter
on the terminal. - Next, we need to install the
ipywidgets
extension, which is necessary to use the widgets in several of our notebooks. Enterpip3 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.