Wie man AttributeError repariert: module 'scipy' has no attribute 'constants'

Problem:

Beim Versuch, Ihr Python-Projekt auszuführen, sehen Sie eine Fehlermeldung wie

scipy_attribute_error.txt
AttributeError: module 'scipy' has no attribute 'constants'

obwohl Sie scipy bereits importiert haben:

repro_import_scipy.py
import scipy

Lösung

Sie müssen scipy.constants explizit importieren

fix_imports.py
import scipy.constants

Ich empfehle generell, sowohl scipy als auch scipy.constants zu importieren, falls Sie scipy selbst woanders in Ihrem Code verwenden:

recommended_imports.py
import scipy
import scipy.constants

Check out similar posts by category: Python