Problem importing matplotlib in Python

  • Context: Python 
  • Thread starter Thread starter PeroK
  • Start date Start date
  • Tags Tags
    Matplotlib Python
Click For Summary

Discussion Overview

The discussion revolves around issues related to importing the matplotlib library in Python, specifically focusing on error messages encountered during the import process. Participants explore potential causes and solutions, including file conflicts and package management methods.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Exploratory

Main Points Raised

  • One participant reports an AttributeError related to the 'numbers' module when trying to import matplotlib after installing it on Python 3.8.3.
  • Another participant inquires whether the user is utilizing pip or anaconda for package management.
  • It is suggested that there may be a conflicting 'numbers.py' file in the user's PYTHONPATH that is interfering with the import process.
  • A participant provides links to external resources discussing similar issues, indicating that this problem has been encountered by others.
  • One participant advises checking for a user-defined 'numbers.py' file and renaming it to resolve the conflict.
  • The original poster confirms that removing the conflicting file resolved the issue.
  • Another participant mentions their preference for using anaconda over pip due to its convenience in managing dependencies in isolated environments.

Areas of Agreement / Disagreement

Participants generally agree on the potential cause of the issue being a conflicting 'numbers.py' file, and the discussion resolves around identifying and fixing this conflict. However, there is no consensus on the preferred package management method, as some favor pip while others prefer anaconda.

Contextual Notes

The discussion highlights the importance of understanding the Python search path and potential conflicts with user-defined module names, which can lead to import errors. Specific details about the user's environment and configurations may influence the applicability of the proposed solutions.

PeroK
Science Advisor
Homework Helper
Insights Author
Gold Member
2025 Award
Messages
29,511
Reaction score
21,278
TL;DR
Installed successfully but won't import
I'm running Python 3.8.3 on Windows 10 and was have installed matplotlib, but I can't get it to work. If I try import matplotlib then first it seems to spit out some output (always the same) from a couple of basic test programs I wrote (which is really weird), then just gets a bunch of errors:

c=300000000
Favorite number is 1729
Traceback (most recent call last):
File "C:\Users\pero_\OneDrive\Documents\python_work\mpl_squares.py", line 1, in <module>
import matplotlib
File "C:\Users\pero_\AppData\Roaming\Python\Python38\site-packages\matplotlib\__init__.py", line 139, in <module>
from . import cbook, rcsetup
File "C:\Users\pero_\AppData\Roaming\Python\Python38\site-packages\matplotlib\cbook\__init__.py", line 32, in <module>
import numpy as np
File "C:\Users\pero_\AppData\Roaming\Python\Python38\site-packages\numpy\__init__.py", line 145, in <module>
from . import core
File "C:\Users\pero_\AppData\Roaming\Python\Python38\site-packages\numpy\core\__init__.py", line 70, in <module>
from . import numerictypes as nt
File "C:\Users\pero_\AppData\Roaming\Python\Python38\site-packages\numpy\core\numerictypes.py", line 596, in <module>
_register_types()
File "C:\Users\pero_\AppData\Roaming\Python\Python38\site-packages\numpy\core\numerictypes.py", line 591, in _register_types
numbers.Integral.register(integer)
AttributeError: module 'numbers' has no attribute 'Integral'
[Finished in 0.9s]

I've been down a rabbit hole with this most of the day. I've tried what I found here, messing about with different WHL files:

https://ehmatthes.github.io/pcc/chapter_15/README.html#installing-matplotlib-on-windows

Any ideas?

Thanks
 
Technology news on Phys.org
Are you using pip or anaconda?

It looks like you have a numbers.py file somewhere in your python search path aka PYTHONPATH that is being processed over the correct one needed by numerictypes.py
 
pip
 
How do I fix that?
 
Look through your code to see if you have a file you named numbers.py
and change its name.
 
  • Informative
  • Like
Likes   Reactions: Borg and PeroK
Aha, that was the test program that was printing the speed of light and the number 1729.

It's gone and that seems to have fixed it. Thanks a million!
 
Great, I’m glad that was easy to find. We don’t use pip for our projects instead we use anaconda which comes loaded with a lot of modules all in one tar because works better in an airgapped environment with no internet access.
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
7K
  • · Replies 11 ·
Replies
11
Views
3K
Replies
9
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 9 ·
Replies
9
Views
9K
  • · Replies 2 ·
Replies
2
Views
2K
Replies
5
Views
15K
  • · Replies 14 ·
Replies
14
Views
2K
  • · Replies 3 ·
Replies
3
Views
3K