Python3.6+Anaconda环境下Matplotlib导入报错:AttributeError: module 'numbers' has no attribute 'Integral'
AttributeError: module 'numbers' has no attribute 'Integral' in Matplotlib (Python 3.6 + Anaconda) Hey there! Let's break down how to fix this frustrating error you're hitting when importing matplotlib. This issue usually boils down to version compatibility or a simple naming conflict—here are the most common fixes:
1. Install a Matplotlib version compatible with Python 3.6
Python 3.6 is no longer supported by newer versions of matplotlib (versions >=3.4 dropped support for 3.6). You'll need to install a version that works with your Python release:
- Open your Anaconda prompt and run:
If you prefer using pip (though Anaconda environments work best with conda), use:conda install matplotlib=3.3.4pip install matplotlib==3.3.4
2. Check for a local file naming conflict
Sometimes, if you have a file named numbers.py in your working directory, it will override Python's built-in numbers module—this is a super common gotcha! To verify:
- Run these lines in your Python shell:
import numbers print(numbers.__file__)
If the output points to a file in your project folder (not the standard library directory like .../anaconda3/lib/python3.6/numbers.py), rename your local numbers.py to something else (like my_numbers.py) and delete any corresponding numbers.pyc file.
3. Create a fresh Anaconda environment (if the above don't work)
Corrupted environments can cause weird dependency issues. Let's make a clean environment tailored to your setup:
- Run these commands in sequence:
conda create -n py36_matplotlib python=3.6 matplotlib=3.3.4 conda activate py36_matplotlib
Now try importing matplotlib again in this new environment—this should eliminate any lingering environment-specific bugs.
Give these steps a try, and let me know if you still run into issues!
内容的提问来源于stack exchange,提问作者O. Edward

