Knowledge Base

The AB Electronics UK Knowledge Base provides support solutions, tutorials and troubleshooting guides.

Knowledge Base

Using Pythonpath with the Python Libraries

Adding the library path to startup

This page details how to add the PYTHONPATH and PATH variables on the Raspberry Pi OS image from https://www.raspberrypi.org/software/operating-systems/ to use with our Python libraries, allowing you to use the libraries from your scripts from any directory on your Raspberry Pi.

Step 1: Download the Python library from our GitHub Repository and extract the library to the directory of your choice, i.e. ABElectronics_Python_Libraries/ADCPi.

Step 2: Use CD to change to the directory containing the library files.

cd ABElectronics_Python_Libraries/ADCPi

Step 3: Use the pwd command to obtain the full directory path.

pwd

This will return the full path to the directory: /home/pi/Desktop/ABElectronics_Python_Libraries/ADCPi.

Step 3 a:  We now edit the .bashrc file to include the library folder in the PATH and PYTHONPATH variables

sudo nano ~/.bashrc

Step 4:  Add the following lines to the .bashrc file at the end, and replace this demo path with the correct location on your computer.

PATH="${PATH}:/home/pi/Desktop/ABElectronics_Python_Libraries/ADCPi"
export PATH

PYTHONPATH="${PYTHONPATH}:/home/pi/Desktop/ABElectronics_Python_Libraries/ADCPi"

export PYTHONPATH

Save your changes and exit the Nano editor.

Step 5: Reboot to apply the changes

sudo reboot

When your Raspberry Pi has rebooted, you will have PYTHONPATH setup for Python 2 or 3 support.


Was this article helpful? Yes No

Please tell us how we can improve this article:

Submit
Created 31/01/2016 | Last Updated: 25/10/2023

Related Expansion Boards

Related Articles

Raspberry Pi GPIO Pin Usage
Raspberry Pi GPIO Pin mapping and connections
PCB Header Assembly Jig
Using the PCB Header Assembly Jig
Samba Setup on Raspberry Pi
How to install and setup Samba on the Raspberry Pi
Set a static IP Address on Raspberry Pi OS Bookworm
How to use a static network IP Address on the Raspberry Pi
Set a static IP Address on Raspberry Pi OS Buster
How to use a static network IP Address on the Raspberry Pi
Set a static IP Address on Raspberry Pi OS Wheezy
Static Network IP Address Setup on the Raspberry Pi
I2C Part 1 - Introducing I2C
An introduction to the I²C protocol
I2C Part 2 - Enabling I2C on the Raspberry Pi
How to enable I2C on the Raspberry Pi
I2C Part 3 - I2C tools in Linux
An introduction to I²C tools in Linux
I2C Part 4 - Programming I2C with Python
How to get started with Programming I²C with Python
SPI and Python on Raspberry Pi OS
Enabling SPI on the Raspberry Pi and installing python py-spidev
Using Pythonpath with the Python Libraries
Adding the library path to startup
Connecting Expansion Boards to the Raspberry Pi 400
Expanding the Potential of Your Raspberry Pi 400