BACKGROUND:
I seem to be marching steadily backwards on trying to use matplotlib and pi_pol with a new user. I can’t seem to get my pi 4 running Buster to find all the files I need. The following is some background, before I ask the question.
First of all, I try a simple matplotlib plot from my new user, which has super user privileges. When I run the simple python3 program, it fails with the following.
Code: Select all
newuser@pi08:~ $ python3 temp_plt02
No protocol specified
qy.qpa.screen: QXcbConnection: Could not connect to display :0.0
Cound not connect to any X display.Code: Select all
pi@pi08:~ $ export DISPLAY=:0.0
pi@pi08:~ $ Xhost +
Code: Select all
LibEGL warning: DRI2: failed to create dri screen
LibEGL warning: DRI2: could not open /dev/dri/card1 (Permission denied)
etcSo, now that I see matplotlib plots from my new user, I try the following program, temp_plt03, taken from https://py-pol.readthedocs.io/en/latest ... care.html.
Code: Select all
#!/usr/bin/env python3
# Poincare Sphere
import matplotlib
matplotlib.use('Qt5Cairo')
import matplotlib.pyplot as plt
import numpy as np
from py_pol import degrees
from py_pol.stokes import Stokes
from py_pol.mueller import Mueller
from py_pol.drawings import draw_poincare_sphere, draw_on_poincare
manifolds=1
inputs=2
s0=Stokes('s_0')
s0.linear_light(angle=0, intensity=2)
print(s0)
s0.draw_poincare(filename='poincare1.png')
plt.legend()Code: Select all
newuser@pi08:~ $ python3 /home/pi/temp_plt03
s_0 = [ +2; +2; +0; +0]
libEGL warning: DRI2: failed to create dri screen
libEGL warning: DRI2: could not open /dev/dri/card1 (Permission denied)
QStandardPaths: wrong ownership on runtime directory /run/user/1000,
1000 instead of 1001 qt5ct: using qt5ct plugin
/usr/lib/python3/dist-packages/matplotlib/tight_layout.py:231:
UserWarning: tight_layout : falling back to Agg renderer
warnings.warn("tight_layout : falling back to Agg renderer")
newuser@pi08:~$ exitCode: Select all
pi@pi08:~ $ python3 temp_plt03
qt5ct: using qt5ct plugin
/usr/lib/python3/dist-packages/matplotlib/tight_layout.py:231:
UserWarning: tight_layout : falling back to Agg renderer
warnings.warn("tight_layout : falling back to Agg renderer") Code: Select all
pi@pi08:~ $ su newuser
Password:
newuser@pi08:/home/pi $ cd ~
newuser@pi08:~ $ sudo python3 /home/pi/temp_plt03
Traceback (most recent call last):
File "/home/pi/temp_plt03", line 7, in <module>
from py_pol import degrees
ModuleNotFoundError: No module named 'py_pol'So, I look through the py_pol install which I did previous to all of this, using pip3 install py_pol. I see at the bottom of the install, it has a series of warnings.
Code: Select all
Installing collected packages: scipy, mpmath, sympy, packaging,
sphinxcontrib-htmlhelp, sphinxcontrib-applehelp,
sphinxcontrib-serializinghtml, sphinxcontrib-qthelp, imagesize,
snowballstemmer, sphinxcontrib-devhelp, alabaster, pytz, babel,
sphinxcontrib-jsmath, sphinx, pandocfilters, defusedxml, mistune,
testpath, bleach, attrs, pyrsistent, jsonschema, nbformat, nbconvert,
nbsphinx, h5py, dill, hickle, py-pol [color=#BF0000]The script isympy is installed in
'/home/pi/.local/bin' which is not on PATH. Consider adding this
directory to PATH[/color] or, if you prefer to suppress this warning, use
--no-warn-script-location. The script pybabel is installed in
'/home/pi/.local/bin' which is not on PATH. Consider adding this
directory to PATH or, if you prefer to suppress this warning, use
--no-warn-script-location. The scripts sphinx-apidoc, sphinx-autogen,
sphinx-build and sphinx-quickstart are installed in
'/home/pi/.local/bin' which is not on PATH. Consider adding this
directory to PATH or, if you prefer to suppress this warning, use
--no-warn-script-location. The script jsonschema is installed in
'/home/pi/.local/bin' which is not on PATH. Consider adding this
directory to PATH or, if you prefer to suppress this warning, use
--no-warn-script-location. The script jupyter-trust is installed in
'/home/pi/.local/bin' which is not on PATH. Consider adding this
directory to PATH or, if you prefer to suppress this warning, use
--no-warn-script-location. The script jupyter-nbconvert is installed in
'/home/pi/.local/bin' which is not on PATH. Consider adding this
directory to PATH or, if you prefer to suppress this warning, use
--no-warn-script-location. The script py_pol is installed in
'/home/pi/.local/bin' which is not on PATH. Consider adding this
directory to PATH or, if you prefer to suppress this warning, use
--no-warn-script-location.So, I try the least intrusive first. I add /home/adi/.local/bin to crontab on my new user. I try it all again. Same result as above. I try adding it to crontab on “pi.” Try it all again; same result. I add it to /etc/profile in the new user. Same result. I try adding it to /etc/environment. There was no such file, so I added it. Tried it all again. Same result. I edited PATH in /etc/login.defs. Same result.The first place where PATH is set is /etc/login.defs. There's a setting for root and a setting for everyone else.
Another place where you can define environment variables is /etc/environment. These settings will apply to everyone (you can't write arbitrary shell code there).
A third place where you can define environment variables is /etc/profile. There you can write arbitrary shell code. If you want a user-specific setting, there is the corresponding per-user file ~www-data/.profile. But this will only apply to console interactive logins; in particular it won't apply to cron jobs unless they explicitly source /etc/profile.
If you only need that PATH setting in a user crontab, you can write it at the beginning of the crontab. Note that you need the full list (PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/zend/bin), you can't use a variable substitution (PATH=$PATH:/usr/local/zend/bin won't work there).
I’m at a loss. What is going on here where I install py_plot so neither my new user nor “pi” can find it?