py-nrf24
py-nrf24 copied to clipboard
Python version confusion
I was using a Pi Zero W with Python 3.9 :
$ python --version
Python 3.9.2
After following the "Quick installation of pigpio on Raspbian:" in README.md :
$ sudo apt-get update
$ sudo apt-get install pigpio python-pigpio python3-pigpio
the default Python version changed to 2.7 :
$ python --version
Python 2.7.18
Calling simple-receiver.py with "python" gives an error:
$ python simple-receiver.py
File "simple-receiver.py", line 34
print(f'Invalid address {address}. Addresses must be between 3 and 5 ASCII characters.')
...but works with "python3"
$ python3 simple-receiver.py
Python NRF24 Simple Receiver Example.
Connecting to GPIO daemon on localhost:8888 ...
Which of the packages in "sudo apt-get install pigpio python-pigpio python3-pigpio" are necessary to have the example working without automatically installing Python v2.7 ?
update:
$ sudo apt-get install python-is-python3
The following packages were automatically installed and are no longer required:
libpython2-stdlib libpython2.7-minimal libpython2.7-stdlib python2 python2-minimal python2.7 python2.7-minimal
Use 'sudo apt autoremove' to remove them.
The following packages will be REMOVED:
python-is-python2 python-pigpio
...
$ python --version
Python 3.9.2
$ python simple-receiver.py
... works
I'm not sure what caused your initial problem.
In general: try to read the following on selecting the Python version on Linux:
https://linuxconfig.org/how-to-change-from-default-to-alternative-python-version-on-debian-linux
//bjarne
... and by the way: the reason the example only works with Python3 is the f-string used.
//bjarne
The initial problem was caused by "sudo apt-get install pigpio python-pigpio python3-pigpio" from the README.md . It seems that one package requires Python 2 and is not necessary, I think it's "python-pigpio". So you may adapt your documentation to "sudo apt-get install pigpio python3-pigpio".