I've been doing a bit of research and there seems to be as many opinions for and against using sudo with pip as there are people responding to the question. Distilled into the two options however:
For:
All other software is installed using sudo.
Using sudo ensures the software is installed system wide and is therefore available for all users.
Some software expects it, eg adafruit-circuitpython-ads1x15.
Against:
The software installed using apt is curated by the package maintainer, whereas there have been instances of bad pip scripts turning up.
If there is only one user, then sudoless pip install is perfectly OK.
In the case of adafruit-circuitpython-ads1x15 we should probably use sudo because Adafruit say so, but otherwise sudoless pip should be used.
pi@g4bypassgatepi:~ $ pip3 install mysqlclient==2.0.1
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting mysqlclient==2.0.1
Downloading https://www.piwheels.org/simple/mysqlclient/mysqlclient-2.0.1-cp37-cp37m-linux_armv6l.whl (106kB)
100% |████████████████████████████████| 112kB 490kB/s
Installing collected packages: mysqlclient
Successfully installed mysqlclient-2.0.1
pi@g4bypassgatepi:~ $ cd rivercontrolsystem
pi@g4bypassgatepi:~/rivercontrolsystem $ ./main.py --id="VALVE4"
Unexpected error
Traceback (most recent call last):
File "/home/pi/.local/lib/python3.7/site-packages/MySQLdb/__init__.py", line 18, in <module>
from . import _mysql
ImportError: libmariadb.so.3: cannot open shared object file: No such file or directory
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "./main.py", line 970, in <module>
run_standalone()
File "./main.py", line 213, in run_standalone
from Tools import coretools as core_tools
File "/home/pi/rivercontrolsystem/Tools/coretools.py", line 42, in <module>
import MySQLdb as mysql
File "/home/pi/.local/lib/python3.7/site-packages/MySQLdb/__init__.py", line 24, in <module>
version_info, _mysql.version_info, _mysql.__file__
NameError: name '_mysql' is not defined
while running. Exiting...
Traceback (most recent call last):
File "/home/pi/.local/lib/python3.7/site-packages/MySQLdb/__init__.py", line 18, in <module>
from . import _mysql
ImportError: libmariadb.so.3: cannot open shared object file: No such file or directory
This was the problem. Now to see if the mysqlclient version is critical.
Hmm, I think the mysqlclient version might be something to do with staying compatible with the very old database software on the NAS box - I'd leave that for now.
I think some dependency must be missing, I'll have a look later today with my pi if I get some time - currently getting car serviced.