About Us Knowledge Base Community Forum Electronics Toolbox FAQ Shipping & Delivery

Community Forum

Share your projects and post your questions

Search
Register or Sign In
Forum

PYTHONPATH

1248 Views - Created 05/04/2016

05/04/2016

Posted by:
Texy

Users Avatar

Hi,

I have been using the ADCPiPlus board for a while, but couldn't get the PYTHONPATH environmental to work so I just copied the relevant files to the same directory as the python script. I have just moved from Wheezy to Jessie on a raspberry pi 2 and rebuilding the OS for this project, but still have the same issue. The Libraries and PYTHONPATH are set to /home/pi/ABElectronics_Python_Libraries/ADCPi/ but it still replies with the error that it can't find the relevant files. Is the envirnomental PYTHONPATH supported?

Also can you confirm that PYTHONPATH is cleared upon a reboot, as it appears to be.

Thanks,

Texy

05/04/2016

Posted by:
JonWeston

Users Avatar

I'm having this issue too on Pi 3

05/04/2016

Posted by:
andrew

Users Avatar

Location:
United Kingdom

Users Twitter  Users Website  

PYTHONPATH should work on the Raspberry Pi.  I have just tried setting up a path to the ADCPi library folder on my Raspberry Pi 2 with the latest Jessi image and I could run the demo-readvoltage.py after moving it to the /home/pi/ folder. 

PYTHONPATH is cleared on reboot but you can get around this by adding the path into the ~/.bashrc file which is parsed on boot.  Open the .bashrc file using nano with the following command.

sudo nano ~/.bashrc

Move to the end of the file and add the following lines:

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

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

Hopefully after you reboot the path will be visible to python so you will be able to run scripts which use the ADCPi library from anywhere in the file system.

I haven't tried this on the Raspberry Pi 3 as my development system is on a Raspberry Pi 2 but as they are both running the same version of Raspian linux it should work fine.  Just to make sure I will try setting up a new image on a Raspberry Pi 3 and check it works.

AB Electronics UK Tech Support

Note: documents in Portable Document Format (PDF) require Adobe Acrobat Reader 5.0 or higher to view, download Adobe Acrobat Reader or other PDF reading software for your computer or mobile device.