2

to install matplotlib library its recomended uses this base:

python -m pip install -U pip
python -m pip install -U matplotlib

when I execute the following code:

(base) C:\WINDOWS\system32>python -m pip install -U pip

results in this warning:

 WARNING: Ignoring invalid distribution -atplotlib (c:\programdata\anaconda3\lib\site-packages)
 WARNING: Ignoring invalid distribution -atplotlib (c:\programdata\anaconda3\lib\site-packages)
 Requirement already satisfied: pip in c:\programdata\anaconda3\lib\site-packages (22.0.4)
 WARNING: Ignoring invalid distribution -atplotlib (c:\programdata\anaconda3\lib\site-packages)
 WARNING: Ignoring invalid distribution -atplotlib (c:\programdata\anaconda3\lib\site-packages)
 WARNING: Ignoring invalid distribution -atplotlib (c:\programdata\anaconda3\lib\site-packages)

so with -U matplotlib do:

WARNING: Ignoring invalid distribution -atplotlib (c:\programdata\anaconda3\lib\site-packages)
WARNING: Ignoring invalid distribution -atplotlib (c:\programdata\anaconda3\lib\site-packages)
Requirement already satisfied: matplotlib in c:\programdata\anaconda3\lib\site-packages (3.5.1)
Requirement already satisfied: numpy>=1.17 in c:\programdata\anaconda3\lib\site-packages (from matplotlib) (1.20.1)
Requirement already satisfied: kiwisolver>=1.0.1 in c:\programdata\anaconda3\lib\site-packages (from matplotlib) (1.3.1)
Requirement already satisfied: pyparsing>=2.2.1 in c:\programdata\anaconda3\lib\site-packages (from matplotlib) (2.4.7)
Requirement already satisfied: packaging>=20.0 in c:\programdata\anaconda3\lib\site-packages (from matplotlib) (20.9)
Requirement already satisfied: fonttools>=4.22.0 in c:\programdata\anaconda3\lib\site-packages (from matplotlib) (4.29.1)
Requirement already satisfied: pillow>=6.2.0 in c:\programdata\anaconda3\lib\site-packages (from matplotlib) (8.2.0)
Requirement already satisfied: cycler>=0.10 in c:\programdata\anaconda3\lib\site-packages (from matplotlib) (0.10.0)
Requirement already satisfied: python-dateutil>=2.7 in c:\programdata\anaconda3\lib\site-packages (from matplotlib) (2.8.1)
Requirement already satisfied: six in c:\programdata\anaconda3\lib\site-packages (from cycler>=0.10->matplotlib) (1.15.0)
WARNING: Ignoring invalid distribution -atplotlib (c:\programdata\anaconda3\lib\site-packages)
WARNING: Ignoring invalid distribution -atplotlib (c:\programdata\anaconda3\lib\site-packages)
WARNING: Ignoring invalid distribution -atplotlib (c:\programdata\anaconda3\lib\site-packages)

and lastly, when I execute import matplotlib.pyplot as plt resuts in:

AttributeError                            Traceback (most recent call last)
<ipython-input-5-310f65eff20b> in <module>
      1 import networkx as nx
----> 2 import matplotlib.pyplot as plt
      3 import pandas as pd

C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\__init__.py in <module>
    875 # triggering resolution of _auto_backend_sentinel.
    876 rcParamsDefault = _rc_params_in_file(
--> 877     cbook._get_data_path("matplotlibrc"),
    878     # Strip leading comment.
    879     transform=lambda line: line[1:] if line.startswith("#") else line,

C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\cbook\__init__.py in _get_data_path(*args)
    478     return a file object, otherwise just a file path.
    479 
--> 480     Sample data files are stored in the 'mpl-data/sample_data' directory within
    481     the Matplotlib package.
    482 

AttributeError: module 'matplotlib' has no attribute 'get_data_path' 

I don't know what to do, hope you can help me.

3
  • Possible duplicate of https://stackoverflow.com/questions/63826975/attributeerror-module-matplotlib-has-no-attribute-get-data-path-on-visual-s ? It "smells" like your matplotlib has not installed properly or else your environments are confused somehow. Commented Mar 8, 2022 at 18:22
  • thank you very much, I'll delete this question in case of duplicate Commented Mar 8, 2022 at 18:30
  • Only delete if the other answer answers your question! Otherwise add enough information to differentiate your question from that other one and there will hopefully be a fix proposed. Commented Mar 8, 2022 at 18:31

4 Answers 4

12

Go to the location in the warning and look for folders starting with "~", if you find any, delete them and rerun the code.

Sign up to request clarification or add additional context in comments.

3 Comments

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
Deleting the folders starting with '~' helped. Thank you very much! I did the upgrade of version and after that started to show the warning. The folders with '~' had previous version number in name. So I believe there was some confusion, as described above in comment from @Pam.
(kill the python process that handle them first)
1

It seems like you may have installed it incorrectly. Try executing

pip show matplotlib

Does it show the version installed?

If you are using anaconda, it should be installed through

conda install matplotlib

Comments

0

Open terminal (i.e., cmd) and go to the problematic folder, in your case c:\programdata\anaconda3\lib\site-packages but on my computer c:\python310\lib\site-packages. Then remove all the directories starting with ~, in my case:

~ip
~ip-22.1.2.dist-info

using the command from here:

for /f %i in ('dir /a:d /s /b ~*') do rd /s /q %i

then try upgrading pip again to be sure things are OK now:

python -m pip install -U pip

interestingly enough, I had the same issue on my macOS device as well on the /usr/local/lib/python3.10/site-packages, and the problematic folders being

~BB
~BB-0.2-py3.10.egg-info

I could easily remove them by going to the said folder and running

rm -rf ~*

Comments

-1

Whether you encounter this problem when trying to install matplotlib or sqlalchemy the fix is simple and the same.

Try locating the folder it returns, (c:\python310\lib\site-packages) and delete any folder starting with ~

1 Comment

How does this answer differ from the answer already posted here?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.