Hi gang,
I’m pretty new to Python and I’ve been banging my head against this for a while. It seems like it would be a simple fix but I am missing what it is.
So here is the error and I’ll explain a curve ball after. Note I’ve truncated the paths in the error.
$ python3
Python 3.6.8 (default, Oct 25 2023, 15:15:22)
[GCC 8.5.0 20210514 (Red Hat 8.5.0-20)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib.py as plt
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/<...>/lib/python3.6/site-packages/matplotlib/__init__.py", line 917, in <module>
fail_on_error=True)
File "/<...>/lib/python3.6/site-packages/matplotlib/__init__.py", line 812, in _rc_params_in_file
with _open_file_or_url(fname) as fd:
File "/usr/lib64/python3.6/contextlib.py", line 81, in __enter__
return next(self.gen)
File "/<...>/lib/python3.6/site-packages/matplotlib/__init__.py", line 786, in _open_file_or_url
fname = os.path.expanduser(fname)
File "/usr/lib64/python3.6/posixpath.py", line 235, in expanduser
path = os.fspath(path)
TypeError: expected str, bytes or os.PathLike object, not PosixPath
>>>
This is on Rocky Linux 8.8.
So the history here is that I have a user who created a script that uses matplotlib. This import works fine in his original ‘/home/user/.local/’ environment. Note that the /home is not local but an NFS mount.
The purpose of his script is for other users to make use of it. So we took his entire ‘./local’ python directory and copied it out to a team NFS share and adjusted permissions so that everyone can use it.
We then configured a profile.d script on specific hosts that sets users who login to point their $PYTHONPATH, $PATH and $LD_LIBRARY_PATH to site-packages, bin and lib respectively to the new share. It all seems to works fine until matplotlib is exported. At which point it fails with the titled error.
I’ve been scouring the internet for a week (working on this as I have time) and I’ve uninstalled and reinstalled matplotlib a few times. Checked and tested different permissions but no go. Python appears to function fine. What I do not know is what it is about the copying of the environment that causes matplotlib to break. It even breaks for the original creator if we point him to the new share.
Any insight would be appreciated.
Edit: It shows installed on the same user it will fail on.
$ python3 -m pip show matplotlib
Name: matplotlib
Version: 3.3.4
Summary: Python plotting package
Home-page: https://matplotlib.org
Author: John D. Hunter, Michael Droettboom
Author-email: matplotlib-users@python.org
License: PSF
Location: /<…>/lib/python3.6/site-packages
Requires: cycler, kiwisolver, numpy, pillow, pyparsing, python-dateutil
Required-by: descartes, mizani, plotnine, scikit-image