Greetings!
Background:
I am attempting to do some experiments with my GoPiGo3 robot, attempting to add a mutex to the SPI communication routines. I want to do this because I would like to use a GPIO Waveshare e-Paper display that uses a separate SPI channel that the GoPiGo controller doesn’t use.[1]
There appears to be a conflict/collision between the two devices, so I want to try a mutex to force them to cooperate.
The robot is using a Pi-4 running Raspberry Pi O/S Buster.
I am using Thonny as my primary programming IDE.
Note that Buster is a hard requirement for this robot’s libraries and code and it cannot be changed. (I say this because every time I say “Buster” folks say “Upgrade to Bookworm!!” and that is not possible at the present time.)
There is an egg file located at
/home/pi/.local/lib/python3.7/site-packages/gopigo3-1.3.2.1-py3.7.egg
.
This is the system default library path for the special GoPiGo3 function libraries.
I want it to use the gopigo3 library files that I have copied from that egg file into /home/pi/Test_Libraries/
, entirely ignoring the existing egg file.
The reason for this is I want to specify my experimental files that I will edit to create a mutex wrapper around the existing SPI code. In order to do this, I have to be able to guarantee that my local python libraries are being used instead of the default libraries within the egg file.
Issue:
I want to force the python path to somewhere else for certain libraries and it doesn’t seem to work.
Looking around the internet, I have done the following based on suggestions from Stack Overflow and others:
Set the python path within a terminal window:
pi@CharlineWiFi:~ $ export PYTHONPATH=${PYTHONPATH}:/home/pi/Test_Libraries/easygopigo3.py
pi@CharlineWiFi:~ $ export PYTHONPATH=${PYTHONPATH}:/home/pi/Test_Libraries/easysensors.py
pi@CharlineWiFi:~ $ export PYTHONPATH=${PYTHONPATH}:/home/pi/Test_Libraries/gopigo3.py
pi@CharlineWiFi:~ $ echo ${PYTHONPATH}
:/home/pi/Test_Libraries/:/home/pi/Test_Libraries/easygopigo3.py:/home/pi/Test_Libraries/easysensors.py:/home/pi/Test_Libraries/gopigo3.py
pi@CharlineWiFi:~ $
Restarting Thonny I see the following in the RPL shell:
Python 3.7.3 (/usr/bin/python3)
>>> import easygopigo3 as easy
>>> print(str(easy))
<module 'easygopigo3' from '/home/pi/.local/lib/python3.7/site-packages/gopigo3-1.3.2.1-py3.7.egg/easygopigo3.py'>
>>>
I edited the .pypath file as follows:
/usr/local/lib/python2.7/dist-packages/gopigo3-1.2.0-py2.7.egg
/usr/local/lib/python2.7/dist-packages/gopigo3-1.2.0-py2.7.egg
/home/pi/Test_Libraries/*
/home/pi/Test_Libraries/easygopigo3.py
/home/pi/Test_Libraries/easysensors.py
/home/pi/Test_Libraries/gopigo3.py
Then I added the following to the end of the .bashrc file:
# export python path
export PYTHONPATH=${PYTHONPATH}:/home/pi/Test_Libraries/:/home/pi/Test_Libraries/easygopigo3.py:/home/pi/Test_Libraries/easysensors.py:/home/pi/Test_Libraries/gopigo3.py
I rebooted the robot and then executed the following in a terminal:
pi@CharlineWiFi:~ $ echo ${PYTHONPATH}
:/home/pi/Test_Libraries/:/home/pi/Test_Libraries/easygopigo3.py:/home/pi/Test_Libraries/easysensors.py:/home/pi/Test_Libraries/gopigo3.py
pi@CharlineWiFi:~ $
. . . and it returns the desired path.
However, when I open Thonny and run:
import easygopigo3 as easy
print(str(easy))
I get the following response in the RPL window:
Python 3.7.3 (/usr/bin/python3)
>>> %Run Python_Path.py
<module 'easygopigo3' from '/home/pi/.local/lib/python3.7/site-packages/gopigo3-1.3.2.1-py3.7.egg/easygopigo3.py'>
>>>
Note that this is still the default system path to the library .egg file instead of my custom installation of these libraries.
Request:
How do I:
- Set the python path for my libraries at the system level so every robot function uses these libraries?
- Set the python path so that Thonny uses the desired path when I am testing code in Thonny?
Bonus question:
Is it possible to completely stop and restart all the robot functions without rebooting?
Thanks in advance for any help you can provide.
========== Footnotes: ==========
- The GoPiGo3 controller board is set to use chip-select-1 (CS-1) and the Waveshare e_Paper display is set to use chip-select-0 (CS-0)