#1 Le 08/12/2019, à 13:59
- Greg_03
[PYTHON] ImportError myplotlib.pyplot
Bonjour,
Dans le cadre de mes cours, je dois utiliser le module myplotlib.pyplot . Je l'ai donc installé via pip, mais lorsque je veux l'utiliser dans mon script, python me retourne l'erreur suivante :
Original exception was:
Traceback (most recent call last):
File "test.py", line 1, in <module>
import matplotlib.pyplot as plt
File "/home/greg/.local/lib/python3.8/site-packages/matplotlib/pyplot.py", line 2349, in <module>
switch_backend(rcParams["backend"])
File "/home/greg/.local/lib/python3.8/site-packages/matplotlib/__init__.py", line 833, in __getitem__
plt.switch_backend(rcsetup._auto_backend_sentinel)
File "/home/greg/.local/lib/python3.8/site-packages/matplotlib/pyplot.py", line 213, in switch_backend
switch_backend("agg")
File "/home/greg/.local/lib/python3.8/site-packages/matplotlib/pyplot.py", line 221, in switch_backend
backend_mod = importlib.import_module(backend_name)
File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "/home/greg/.local/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py", line 45, in <module>
from PIL import Image
File "/usr/lib/python3/dist-packages/PIL/Image.py", line 94, in <module>
from . import _imaging as core
ImportError: cannot import name '_imaging' from 'PIL' (/usr/lib/python3/dist-packages/PIL/__init__.py)
J'ai essayé de désinstaller le module et de le réinstaller ensuite, mais rien n'y fait. Auriez-vous une solution à me proposer ?
Merci d'avance
PS : Je suis sous Python 3.8.0
Dernière modification par Greg_03 (Le 08/12/2019, à 14:05)
Hors ligne
#2 Le 08/12/2019, à 15:04
- pingouinux
Re : [PYTHON] ImportError myplotlib.pyplot
Bonjour,
Je l'ai donc installé via pip
................................
PS : Je suis sous Python 3.8.0
Il faut dans ce cas utiliser pip3 et non pip
Hors ligne
#3 Le 08/12/2019, à 15:16
- Greg_03
Re : [PYTHON] ImportError myplotlib.pyplot
Après avoir installé matplotlib via la commande
pip3 install matplotlib
, le problème reste inchangé et python me retourne toujours la même erreur. Ai-je fais une erreur lors de l'installation du module peut-être ?
Hors ligne
#4 Le 08/12/2019, à 15:39
- pingouinux
Re : [PYTHON] ImportError myplotlib.pyplot
En relisant plus attentivement ton premier message, ce n'est pas sur matplotlib.pyplot qu'il râlait, mais sur _imaging :
File "/home/greg/.local/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py", line 45, in <module>
from PIL import Image
File "/usr/lib/python3/dist-packages/PIL/Image.py", line 94, in <module>
from . import _imaging as core
ImportError: cannot import name '_imaging' from 'PIL' (/usr/lib/python3/dist-packages/PIL/__init__.py)
Pas de problème chez moi, mais je n'ai pas la même version de python3
$ python3 --version
Python 3.5.2
Hors ligne
#5 Le 08/12/2019, à 15:45
- Greg_03
Re : [PYTHON] ImportError myplotlib.pyplot
Dans ce cas, comment je peux remédier à mon problème ?
Hors ligne
#6 Le 08/12/2019, à 16:05
- pingouinux
Re : [PYTHON] ImportError myplotlib.pyplot
Dans ce cas, comment je peux remédier à mon problème ?
Je sèche…
Tu peux éventuellement regarder le fichier /usr/lib/python3/dist-packages/PIL/Image.py, notamment la ligne 94, mais j'ai bien peur que ça ne nous en apprenne pas beaucoup.
Hors ligne
#7 Le 08/12/2019, à 16:15
- Greg_03
Re : [PYTHON] ImportError myplotlib.pyplot
Voici la ligne 94 :
from . import _imaging as core
Et voici ce qu'il y a dans le fichier entre les lignes 88 et 101 (si jamais il y en a besoin) :
try:
# If the _imaging C module is not present, Pillow will not load.
# Note that other modules should not refer to _imaging directly;
# import Image and use the Image.core variable instead.
# Also note that Image.core is not a publicly documented interface,
# and should be considered private and subject to change.
from . import _imaging as core
if __version__ != getattr(core, 'PILLOW_VERSION', None):
raise ImportError("The _imaging extension was built for another "
"version of Pillow or PIL:\n"
"Core version: %s\n"
"Pillow version: %s" %
(getattr(core, 'PILLOW_VERSION', None),
__version__))
Dernière modification par Greg_03 (Le 08/12/2019, à 16:15)
Hors ligne
#8 Le 13/12/2019, à 16:45
- Greg_03
Re : [PYTHON] ImportError myplotlib.pyplot
Quelqu'un d'autre aurait une solution à mon problème ?
Hors ligne
#9 Le 01/04/2020, à 13:24
- Greg_03
Re : [PYTHON] ImportError myplotlib.pyplot
Pour ceux qui se retrouveraient face à ce problème, j'ai réussi à régler le problème en passant de python 3.8 à python 3.7.
Hors ligne