Using Pythonpath with the Python Libraries
Adding the library path to startup
Created: 31/01/2016 | Last Updated: 17/02/2021
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 Github 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.
Step 3: Use the pwd command to obtain the full directory path.
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, replace this demo path to the correct location on your computer.
Save your changes and exit the Nano editor.
Step 5: Reboot to apply the changes
When your Raspberry Pi has rebooted you will now have PYTHONPATH to the library setup for Python 2 or 3 support.