Installation
Install PySerial on Windows, Linux, and macOS with pip, conda, or system packages. Covers virtual environments, permissions, and troubleshooting.
Install PySerial and verify it works.
Install PySerial
pip install pyserialUpgrade to latest:
pip install --upgrade pyserialPin a version:
pip install pyserial==3.5conda install -c conda-forge pyserialsudo apt update
sudo apt install python3-serialsudo dnf install python3-pyserialsudo pacman -S python-pyserialPlatform Setup
Windows
Install Python
Download from python.org. Check "Add Python to PATH" during installation.
Install PySerial
pip install pyserialIf you get a permission error:
pip install --user pyserialLinux
Install
pip install pyserialFix Permissions
Serial ports require membership in the dialout group:
sudo usermod -a -G dialout $USER
newgrp dialoutVerify with groups. You should see dialout in the output.
Without dialout group membership, you'll get PermissionError when opening any /dev/tty* port.
macOS
brew install python3
pip3 install pyserialmacOS Catalina and later may require granting Full Disk Access to Terminal (System Preferences, Security and Privacy, Privacy tab).
Virtual Environments
python -m venv serial-project
source serial-project/bin/activate # Linux/macOS
# serial-project\Scripts\activate # Windows
pip install pyserialOr with conda:
conda create -n serial-env python=3.11 pyserial
conda activate serial-envVerify Installation
python -c "import serial; print(serial.__version__)"Expected output: 3.5 (or your installed version).
List connected serial devices:
import serial.tools.list_ports
for port in serial.tools.list_ports.comports():
print(f"{port.device}: {port.description}")Log serial data automatically
TofuPilot records test results from your PySerial scripts, tracks pass/fail rates, and generates compliance reports. Free to start.
Troubleshooting
ModuleNotFoundError: No module named 'serial'
The PyPI package is pyserial, not serial. If you installed the wrong one:
pip uninstall serial
pip install pyserialThe import is import serial (not import pyserial).
Permission Denied (Linux)
sudo usermod -a -G dialout $USER
# Log out and back in, or run: newgrp dialoutPort Not Found
Check that your device is connected:
# Linux
ls /dev/tty{USB,ACM,S}*
# macOS
ls /dev/cu.* /dev/tty.*import serial.tools.list_ports
for port in serial.tools.list_ports.comports():
print(f"{port.device}: {port.description}")Multiple Python Versions
python3.11 -m pip install pyserialOn Windows, use the py launcher:
py -3.11 -m pip install pyserialInstall from Source
git clone https://github.com/pyserial/pyserial.git
cd pyserial
pip install -e .