Getting Started with Python Setup

Last revision 2025/12/17

This article provides a detailed guide on setting up a Python environment, installing essential libraries, and configuring UART on Raspberry Pi devices. It includes specific commands and steps for various Python versions and Raspberry Pi models, ensuring a smooth setup process.

Configuration

Install Library

Check the python version number using the command below before installing the relevant library.

pip --version

DFR0824-version

The commands to build the environment for the version below python3 are as follows

sudo pip install pyserial
sudo pip install modbus_tk

The commands to build the environment for python3 are as follows

sudo pip3 install pyserial
sudo pip3 install modbus_tk

For the Raspberry Pi 5, the following commands are used to set up the environment

sudo pip install pyserial --break-system-packages
sudo pip install modbus_tk --break-system-packages

Enable UART

Open the Raspberry Pi terminal and enter the command below to access the configuration interface.

sudo raspi-config

Select Interfacing Options -> Serial Port, disable shell access and enable hardware serial port

DFR0824-enable hardware serial port

Reboot Raspberry Pi:

sudo reboot

Find the location of the config.txt file

cd /boot

Open the /boot/config.txt file and find the statement below, if there is not, you can add it at the end of the file.

enable_uart=1

DFR0824-save and exit

Then enter the command below to save and exit the file

:wq

For Raspberry Pi 3B users, the serial port is used for Bluetooth and needs to be commented out:

#dtoverlay=pi3-miniuart-bt

Reboot Raspberry Pi

sudo reboot

Make wire connections for the device according to the port instructions when Raspberry Pi is fully configured.

Was this article helpful?

TOP