Reputation: 1233
I'm facing below error while importing matplotlib(version 3.3.2) on ubuntu server.
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.8/site-packages/matplotlib/__init__.py", line 904, in <module>
rcParamsDefault = _rc_params_in_file(
File "/usr/local/lib/python3.8/site-packages/matplotlib/__init__.py", line 803, in _rc_params_in_file
with _open_file_or_url(fname) as fd:
File "/usr/local/lib/python3.8/contextlib.py", line 113, in __enter__
return next(self.gen)
File "/usr/local/lib/python3.8/site-packages/matplotlib/__init__.py", line 777, in _open_file_or_url
fname = os.path.expanduser(fname)
File "/usr/local/lib/python3.8/posixpath.py", line 231, in expanduser
path = os.fspath(path)
TypeError: expected str, bytes or os.PathLike object, not PosixPath
I have tried upgrading to 3.4.1 but still in pip list
it is showing as 3.3.2 version.
Upvotes: 2
Views: 2196
Reputation: 1233
TL;DR
Uninstalled matplotlib from all the installed locations and downgraded to 3.0.3
What I have done
I had matplotlib installed at two different locations.
All the upgrades were getting affected in the package that is installed under path-2. Now I have matplotlib 3.3.2 at path-1 and 3.4.1 in path-2 but python is reading the matplotlib from path-1 as I've seen the same path was given in the output of pip show matplotlib
terminal command. I have added path-2 to the python path with sys.path
function but the error remained same as in the question.
At this point I have uninstalled the matplotlib from both the locations, and reinstalled 3.4.2 version at path-2. Now the pip show matplotlib
got changed to path-2 but it didn't resolve the import error.
I have again uninstalled matplotlib from path-2 and re-installed matplotlib of 3.0.3 version(downgraded from 3.4.2 to 3.0.3). This resolved the error.
Remarks
I have exactly the same configuration in another ubuntu server and matplotlib 3.3.2 version is working without any issue. At this point I'm not sure why it didn't work in this server with 3.3.2 matplotlib but I will surely try to find the root cause.
Upvotes: 4