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: 01/01/2024

Related Expansion Boards

Order a ADC Differential Pi Photo of ADC Differential Pi
ADC Differential Pi

8 Channel 18-bit Differential Analogue to Digital converter for the Raspberry Pi

£17.99 Ex VAT: £14.99
Add to Basket
Order a ADC Pi Photo of ADC Pi
ADC Pi

8 Channel 17-bit Single-Ended Analogue to Digital converter for the Raspberry Pi

£19.19 Ex VAT: £15.99
Add to Basket
Order a Expander Pi Photo of Expander Pi
Expander Pi

Analogue, Digital and RTC Expansion Interface for the Raspberry Pi

£27.59 Ex VAT: £22.99
Add to Basket
Order a I2C Switch Photo of I2C Switch
I2C Switch

4 channel I2C Switch for the Raspberry Pi

£10.79 Ex VAT: £8.99
Add to Basket
Order a IO Pi Plus Photo of IO Pi Plus
IO Pi Plus

32 channel MCP23017 digital I/O expander for the Raspberry Pi

£14.39 Ex VAT: £11.99
Add to Basket
Order a IO Zero 32 Photo of IO Zero 32
IO Zero 32

32 channel digital I/O expander for the Raspberry Pi

£13.19 Ex VAT: £10.99
Add to Basket
Order a RTC Pi Photo of RTC Pi
RTC Pi

Real-time clock for the Raspberry Pi

£11.39 Ex VAT: £9.49
Add to Basket
Order a Servo PWM Pi Photo of Servo PWM Pi
Servo PWM Pi

16-channel, 12-bit PWM controller for driving LEDs and RC servos

£11.39 Ex VAT: £9.49
Add to Basket

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