Knowledge Base
The AB Electronics UK Knowledge Base provides support solutions, tutorials and troubleshooting guides.
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.
Related Expansion Boards
Related Articles
How to use a static network IP Address on the Raspberry Pi
How to use a static network IP Address on the Raspberry Pi
Static Network IP Address Setup on the Raspberry Pi
Expanding the Potential of Your Raspberry Pi 400