#1 Le 17/09/2017, à 10:20
- BUTZ
Python ModuleNotFoundError RÉSOLU
Bonjour à tous,
Sous Kubuntu 16.04, j'ai besoin d'utiliser Python sous Pyzo.
Lorsque je charge le module "matplotlib", je reçois une ModuleNotFoundError :
Voici les premières lignes de ce que je veux exécuter (ce n'est pas dans la Konsole mais dans Pyzo, ne vous fiez pas aux apparences) :
from math import *
import matplotlib.pyplot as plt
et voici le retour du shell :
Kernel process terminated for restart. (0)
Python 3.6.0 |Continuum Analytics, Inc.| (default, Dec 23 2016, 12:22:00) on linux (64 bits).
This is the Pyzo interpreter with integrated event loop for TK.
Type 'help' for help, type '?' for a list of *magic* commands.
Running script: "/home/fred/Documents/Lycée/python/loverdiere/fibon2.py"
Traceback (most recent call last):
File "/home/fred/Documents/Lycée/python/loverdiere/fibon2.py", line 2, in <module>
import matplotlib.pyplot as plt
ModuleNotFoundError: No module named 'matplotlib'
Avant de venir ici vous poser la question, je suis allé là :
https://askubuntu.com/questions/588390/ … -in-python
Pensant avoir trouvé la solution, j'ai fait ce qui suit dans Konsole :
fred@fred-Lenovo-G50-30:~$ python -c "import matplotlib"
Traceback (most recent call last):
File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'matplotlib'
fred@fred-Lenovo-G50-30:~$ echo $?
1
fred@fred-Lenovo-G50-30:~$ sudo apt-get install python3-matplotlib
[sudo] Mot de passe de fred :
Lecture des listes de paquets... Fait
Construction de l'arbre des dépendances
Lecture des informations d'état... Fait
Les paquets suivants ont été installés automatiquement et ne sont plus nécessaires :
libmircommon5 linux-headers-4.4.0-77 linux-headers-4.4.0-77-generic linux-image-4.4.0-77-generic linux-image-extra-4.4.0-77-generic linux-signed-image-4.4.0-77-generic
Veuillez utiliser « sudo apt autoremove » pour les supprimer.
The following additional packages will be installed:
fonts-lyx libjs-jquery-ui python-matplotlib-data python3-cycler python3-dateutil python3-numpy python3-pyparsing python3-tk python3-tz ttf-bitstream-vera
Paquets suggérés :
libjs-jquery-ui-docs dvipng ipython3 python-matplotlib-doc python3-cairocffi python3-gobject python3-nose python3-scipy python3-tornado texlive-latex-extra ttf-staypuft
python-numpy-doc python3-numpy-dbg tix python3-tk-dbg
Les NOUVEAUX paquets suivants seront installés :
fonts-lyx libjs-jquery-ui python-matplotlib-data python3-cycler python3-dateutil python3-matplotlib python3-numpy python3-pyparsing python3-tk python3-tz ttf-bitstream-vera
0 mis à jour, 11 nouvellement installés, 0 à enlever et 293 non mis à jour.
Il est nécessaire de prendre 9 156 ko dans les archives.
Après cette opération, 32,0 Mo d'espace disque supplémentaires seront utilisés.
Souhaitez-vous continuer ? [O/n] o
Réception de:1 http://fr.archive.ubuntu.com/ubuntu xenial/universe amd64 fonts-lyx all 2.1.4-2 [161 kB]
Réception de:2 http://fr.archive.ubuntu.com/ubuntu xenial/universe amd64 libjs-jquery-ui all 1.10.1+dfsg-1 [458 kB]
Réception de:3 http://fr.archive.ubuntu.com/ubuntu xenial/universe amd64 ttf-bitstream-vera all 1.10-8 [352 kB]
Réception de:4 http://fr.archive.ubuntu.com/ubuntu xenial/universe amd64 python-matplotlib-data all 1.5.1-1ubuntu1 [2 414 kB]
Réception de:5 http://fr.archive.ubuntu.com/ubuntu xenial/universe amd64 python3-cycler all 0.9.0-1 [5 532 B]
Réception de:6 http://fr.archive.ubuntu.com/ubuntu xenial/universe amd64 python3-dateutil all 2.4.2-1 [39,1 kB]
Réception de:7 http://fr.archive.ubuntu.com/ubuntu xenial-updates/main amd64 python3-pyparsing all 2.0.3+dfsg1-1ubuntu0.1 [35,5 kB]
Réception de:8 http://fr.archive.ubuntu.com/ubuntu xenial/main amd64 python3-tz all 2014.10~dfsg1-0ubuntu2 [24,6 kB]
Réception de:9 http://fr.archive.ubuntu.com/ubuntu xenial/main amd64 python3-numpy amd64 1:1.11.0-1ubuntu1 [1 762 kB]
Réception de:10 http://fr.archive.ubuntu.com/ubuntu xenial/universe amd64 python3-matplotlib amd64 1.5.1-1ubuntu1 [3 881 kB]
Réception de:11 http://fr.archive.ubuntu.com/ubuntu xenial/main amd64 python3-tk amd64 3.5.1-1 [25,1 kB]
9 156 ko réceptionnés en 6s (1 358 ko/s)
Sélection du paquet fonts-lyx précédemment désélectionné.
(Lecture de la base de données... 315458 fichiers et répertoires déjà installés.)
Préparation du dépaquetage de .../fonts-lyx_2.1.4-2_all.deb ...
Dépaquetage de fonts-lyx (2.1.4-2) ...
Sélection du paquet libjs-jquery-ui précédemment désélectionné.
Préparation du dépaquetage de .../libjs-jquery-ui_1.10.1+dfsg-1_all.deb ...
Dépaquetage de libjs-jquery-ui (1.10.1+dfsg-1) ...
Sélection du paquet ttf-bitstream-vera précédemment désélectionné.
Préparation du dépaquetage de .../ttf-bitstream-vera_1.10-8_all.deb ...
Dépaquetage de ttf-bitstream-vera (1.10-8) ...
Sélection du paquet python-matplotlib-data précédemment désélectionné.
Préparation du dépaquetage de .../python-matplotlib-data_1.5.1-1ubuntu1_all.deb ...
Dépaquetage de python-matplotlib-data (1.5.1-1ubuntu1) ...
Sélection du paquet python3-cycler précédemment désélectionné.
Préparation du dépaquetage de .../python3-cycler_0.9.0-1_all.deb ...
Dépaquetage de python3-cycler (0.9.0-1) ...
Sélection du paquet python3-dateutil précédemment désélectionné.
Préparation du dépaquetage de .../python3-dateutil_2.4.2-1_all.deb ...
Dépaquetage de python3-dateutil (2.4.2-1) ...
Sélection du paquet python3-pyparsing précédemment désélectionné.
Préparation du dépaquetage de .../python3-pyparsing_2.0.3+dfsg1-1ubuntu0.1_all.deb ...
Dépaquetage de python3-pyparsing (2.0.3+dfsg1-1ubuntu0.1) ...
Sélection du paquet python3-tz précédemment désélectionné.
Préparation du dépaquetage de .../python3-tz_2014.10~dfsg1-0ubuntu2_all.deb ...
Dépaquetage de python3-tz (2014.10~dfsg1-0ubuntu2) ...
Sélection du paquet python3-numpy précédemment désélectionné.
Préparation du dépaquetage de .../python3-numpy_1%3a1.11.0-1ubuntu1_amd64.deb ...
Dépaquetage de python3-numpy (1:1.11.0-1ubuntu1) ...
Sélection du paquet python3-matplotlib précédemment désélectionné.
Préparation du dépaquetage de .../python3-matplotlib_1.5.1-1ubuntu1_amd64.deb ...
Dépaquetage de python3-matplotlib (1.5.1-1ubuntu1) ...
Sélection du paquet python3-tk précédemment désélectionné.
Préparation du dépaquetage de .../python3-tk_3.5.1-1_amd64.deb ...
Dépaquetage de python3-tk (3.5.1-1) ...
Traitement des actions différées (« triggers ») pour fontconfig (2.11.94-0ubuntu1.1) ...
Traitement des actions différées (« triggers ») pour man-db (2.7.5-1) ...
Paramétrage de fonts-lyx (2.1.4-2) ...
Paramétrage de libjs-jquery-ui (1.10.1+dfsg-1) ...
Paramétrage de ttf-bitstream-vera (1.10-8) ...
Paramétrage de python-matplotlib-data (1.5.1-1ubuntu1) ...
Paramétrage de python3-cycler (0.9.0-1) ...
Paramétrage de python3-dateutil (2.4.2-1) ...
Paramétrage de python3-pyparsing (2.0.3+dfsg1-1ubuntu0.1) ...
Paramétrage de python3-tz (2014.10~dfsg1-0ubuntu2) ...
Paramétrage de python3-numpy (1:1.11.0-1ubuntu1) ...
Paramétrage de python3-matplotlib (1.5.1-1ubuntu1) ...
Paramétrage de python3-tk (3.5.1-1) ...
fred@fred-Lenovo-G50-30:~$
On voit bien que matplotlib est installé cette fois, mais ça ne change absolument rien, ni avant ni après le redémarrage, ni dans le shell ni dans Konsole.
fred@fred-Lenovo-G50-30:~$ python -c "import matplotlib"
Traceback (most recent call last):
File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'matplotlib'
fred@fred-Lenovo-G50-30:~$ echo $?
1
fred@fred-Lenovo-G50-30:~$
Je crois que ce qu'il manque, c'est maintenant de les importer dans sys.module :
After installation we then can add them to the sys.modules dictionary by importing them once.
Mais je n'en suis pas bien sûr et ne vois pas comment faire.
C'est là que j'attends votre aide avec ma reconnaissance toute prête.
Fred
Dernière modification par BUTZ (Le 20/09/2017, à 16:02)
Hors ligne
#2 Le 17/09/2017, à 11:47
- pingouinux
Re : Python ModuleNotFoundError RÉSOLU
Bonjour,
fred@fred-Lenovo-G50-30:~$ sudo apt-get install python3-matplotlib
Tu as installé le paquet pour python3. Si tu es en python2, il faut installer le paquet python-matplotlib .
Hors ligne
#3 Le 17/09/2017, à 13:41
- BUTZ
Re : Python ModuleNotFoundError RÉSOLU
Bonjour pingouinux
Merci de ta célérité.
Lorsque je vais dans le menu Aide>A propos de Pyzo, je vois écrit : Python version: 3.5.2
C'est ce qui me fait penser que je suis bien sous Python 3.
Penses-tu que c'est naïf de ma part ?
Hors ligne
#4 Le 17/09/2017, à 14:18
- pingouinux
Re : Python ModuleNotFoundError RÉSOLU
Lorsque je vais dans le menu Aide>A propos de Pyzo, je vois écrit : Python version: 3.5.2 C'est ce qui me fait penser que je suis bien sous Python 3.
Je ne connais pas Pyzo, mais ça semble logique.
fred@fred-Lenovo-G50-30:~$ python -c "import matplotlib"
C'est à cause de la ligne ci-dessus que je pensais que tu utilisais python2.
Je suppose que la ligne suivante ne produit pas d'erreur :
python3 -c "import matplotlib"
Pour voir la version utilisée :
import sys
print(sys.version)
Ajouté :
Tu peux aussi regarder ceci (ligne 3.)
Dernière modification par pingouinux (Le 17/09/2017, à 14:39)
Hors ligne
#5 Le 17/09/2017, à 16:07
- BUTZ
Re : Python ModuleNotFoundError RÉSOLU
Je vais voir ce que tu m'indiques.
En attendant, voici ce qu'ont donné tes suggestions :
fred@fred-Lenovo-G50-30:~$ python3 -c "import matplotlib"
Traceback (most recent call last):
File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'matplotlib'
fred@fred-Lenovo-G50-30:~$ import sys
fred@fred-Lenovo-G50-30:~$ print(sys.version)
bash: erreur de syntaxe près du symbole inattendu « sys.version »
fred@fred-Lenovo-G50-30:~$
Hors ligne
#6 Le 17/09/2017, à 16:12
- BUTZ
Re : Python ModuleNotFoundError RÉSOLU
J'ai lancé dans le shell de Pyzo la phrase indiquée dans la ligne 3 du tuto du lycée Kléber et ça ne marche pas :
>>> install numpy scipy matplotlib
File "<console>", line 1
install numpy scipy matplotlib
^
SyntaxError: invalid syntax
Hors ligne
#7 Le 17/09/2017, à 16:17
- pingouinux
Re : Python ModuleNotFoundError RÉSOLU
Pour la première commande, je ne comprends pas.
Pour les deux suivantes, c'est normal, il faut les lancer à partir de l'interpréteur python.
Dernière modification par pingouinux (Le 17/09/2017, à 16:17)
Hors ligne
#8 Le 17/09/2017, à 16:27
- pingouinux
Re : Python ModuleNotFoundError RÉSOLU
En #7, je répondais à ton message #5. Pour le #6, ne connaissant pas Pyzo, je ne sais pas répondre.
Hors ligne
#9 Le 17/09/2017, à 19:26
- BUTZ
Re : Python ModuleNotFoundError RÉSOLU
Suite du #5 donc, dans le shell de Pyzo cette fois :
>>> python3 -c "import matplotlib"
File "<console>", line 1
python3 -c "import matplotlib"
^
SyntaxError: invalid syntax
>>> import sys
>>> print(sys.version)
3.6.0 |Continuum Analytics, Inc.| (default, Dec 23 2016, 12:22:00)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)]
>>>
Hors ligne
#10 Le 18/09/2017, à 07:50
- pingouinux
Re : Python ModuleNotFoundError RÉSOLU
Voici un petit résumé, d'après tes différents messages :
1)
fred@fred-Lenovo-G50-30:~$ sudo apt-get install python3-matplotlib
Il semble donc que tu aies installé le module matplotlib pour python3
2)
Lorsque je vais dans le menu Aide>A propos de Pyzo, je vois écrit : Python version: 3.5.2
>>> import sys >>> print(sys.version) 3.6.0 |Continuum Analytics, Inc.| (default, Dec 23 2016, 12:22:00) [GCC 4.4.7 20120313 (Red Hat 4.4.7-1)]
Tu utilises python3, mais quelle version, 3.5.2 ou 3.6.0 ?
3)
fred@fred-Lenovo-G50-30:~$ python3 -c "import matplotlib" Traceback (most recent call last): File "<string>", line 1, in <module> ModuleNotFoundError: No module named 'matplotlib'
matplotlib ne semble pas connu de python3
4)
Peux-tu donner le retour de ces commandes :
ls -l /usr/bin/python*
dpkg -l | grep matplotlib
Hors ligne
#11 Le 18/09/2017, à 19:32
- BUTZ
Re : Python ModuleNotFoundError RÉSOLU
Bonsoir,
Tu as raison : il y a deux versions différentes ! J'avais oublié avoir installé Python 2 il y a deux ans, comme c'est indiqué dans les réponses suivantes aux commandes que tu as indiquées :
fred@fred-Lenovo-G50-30:~$ ls -l /usr/bin/python*
lrwxrwxrwx 1 root root 9 déc. 10 2015 /usr/bin/python -> python2.7
lrwxrwxrwx 1 root root 9 déc. 10 2015 /usr/bin/python2 -> python2.7
-rwxr-xr-x 1 root root 3546104 nov. 19 2016 /usr/bin/python2.7
lrwxrwxrwx 1 root root 33 nov. 19 2016 /usr/bin/python2.7-config -> x86_64-linux-gnu-python2.7-config
lrwxrwxrwx 1 root root 16 déc. 10 2015 /usr/bin/python2-config -> python2.7-config
lrwxrwxrwx 1 root root 9 mars 23 2016 /usr/bin/python3 -> python3.5
-rwxr-xr-x 2 root root 4460336 nov. 17 2016 /usr/bin/python3.5
lrwxrwxrwx 1 root root 33 nov. 17 2016 /usr/bin/python3.5-config -> x86_64-linux-gnu-python3.5-config
-rwxr-xr-x 2 root root 4460336 nov. 17 2016 /usr/bin/python3.5m
lrwxrwxrwx 1 root root 34 nov. 17 2016 /usr/bin/python3.5m-config -> x86_64-linux-gnu-python3.5m-config
lrwxrwxrwx 1 root root 16 mars 23 2016 /usr/bin/python3-config -> python3.5-config
lrwxrwxrwx 1 root root 10 mars 23 2016 /usr/bin/python3m -> python3.5m
lrwxrwxrwx 1 root root 17 mars 23 2016 /usr/bin/python3m-config -> python3.5m-config
lrwxrwxrwx 1 root root 16 déc. 10 2015 /usr/bin/python-config -> python2.7-config
lrwxrwxrwx 1 root root 58 mars 25 2016 /usr/bin/pythontex -> ../share/texlive/texmf-dist/scripts/pythontex/pythontex.py
-rwxr-xr-x 1 root root 306 mars 25 2016 /usr/bin/pythontex3
et là par contre, je ne sais pas interpréter :
fred@fred-Lenovo-G50-30:~$ dpkg -l | grep matplotlib
ii python-matplotlib-data 1.5.1-1ubuntu1 all Python based plotting system (data package)
ii python3-matplotlib 1.5.1-1ubuntu1 amd64 Python based plotting system in a style similar to Matlab (Python 3)
fred@fred-Lenovo-G50-30:~$
Hors ligne
#12 Le 18/09/2017, à 20:34
- pingouinux
Re : Python ModuleNotFoundError RÉSOLU
Les paquets python-matplotlib-data et python3-matplotlib sont aussi installés chez moi pour utiliser matplotlib en python3.
Je suis intrigué par les 2 versions différentes de python que tu obtiens (voir le paragraphe 2) de mon message #10) : 3.5.2 et 3.6.0
Quel est le retour de
python3 -c "import sys;print(sys.version)"
Hors ligne
#13 Le 18/09/2017, à 22:02
- BUTZ
Re : Python ModuleNotFoundError RÉSOLU
C'est :
fred@fred-Lenovo-G50-30:~$ python3 -c "import sys;print(sys.version)"
3.6.0 |Continuum Analytics, Inc.| (default, Dec 23 2016, 12:22:00)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)]
fred@fred-Lenovo-G50-30:~$
Hors ligne
#14 Le 19/09/2017, à 07:05
- pingouinux
Re : Python ModuleNotFoundError RÉSOLU
python3.6 n'apparaît pas dans la liste en #11.
Que retourne
type python3
Hors ligne
#15 Le 19/09/2017, à 08:03
- BUTZ
Re : Python ModuleNotFoundError RÉSOLU
Ça retourne ceci :
fred@fred-Lenovo-G50-30:~$ type python3
python3 est /home/fred/miniconda3/bin/python3
fred@fred-Lenovo-G50-30:~$
Hors ligne
#16 Le 19/09/2017, à 08:18
- pingouinux
Re : Python ModuleNotFoundError RÉSOLU
Je pense que matplotlib est accessible dans /usr/bin/python3. Si c'est le cas, la commande suivante ne devrait rien retourner.
/usr/bin/python3 -c "import matplotlib"
Tu peux aussi donner le retour de :
ls -ld /home/fred/miniconda3/bin/python*
Hors ligne
#17 Le 19/09/2017, à 08:44
- BUTZ
Re : Python ModuleNotFoundError RÉSOLU
Tu as raison, la première commande ne retourne rien. La seconde est plus bavarde.
fred@fred-Lenovo-G50-30:~$ /usr/bin/python3 -c "import matplotlib"
fred@fred-Lenovo-G50-30:~$ ls -ld /home/fred/miniconda3/bin/python*
lrwxrwxrwx 1 root root 9 juin 5 22:55 /home/fred/miniconda3/bin/python -> python3.6
lrwxrwxrwx 1 root root 9 juin 5 22:55 /home/fred/miniconda3/bin/python3 -> python3.6
-rwxrwxr-x 1 root root 14040 déc. 23 2016 /home/fred/miniconda3/bin/python3.6
lrwxrwxrwx 1 root root 17 juin 5 22:55 /home/fred/miniconda3/bin/python3.6-config -> python3.6m-config
-rwxrwxr-x 2 root root 14040 déc. 23 2016 /home/fred/miniconda3/bin/python3.6m
-rwxrwxr-x 1 root root 3086 juin 5 22:55 /home/fred/miniconda3/bin/python3.6m-config
lrwxrwxrwx 1 root root 17 juin 5 22:55 /home/fred/miniconda3/bin/python3-config -> python3.6m-config
fred@fred-Lenovo-G50-30:~$
Hors ligne
#18 Le 19/09/2017, à 08:50
- BUTZ
Re : Python ModuleNotFoundError RÉSOLU
En voyant tout ça, j'ai l'impression d'avoir installé une première série dans usr/bin et une seconde série dans home/fred/miniconda/bin.
Est-ce qu'il ne faudrait pas tout mettre au même endroit ?
Hors ligne
#19 Le 19/09/2017, à 08:58
- pingouinux
Re : Python ModuleNotFoundError RÉSOLU
Le problème vient certainement de là, mais je ne sais pas tout remettre en place sans risquer de mettre la pagaille.
Le mieux est d'attendre un avis éclairé.
Tu peux déjà donner le retour de
echo "$PATH"
Hors ligne
#20 Le 19/09/2017, à 09:08
- BUTZ
Re : Python ModuleNotFoundError RÉSOLU
Le voici :
fred@fred-Lenovo-G50-30:~$ echo "$PATH"
/home/fred/miniconda3/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
fred@fred-Lenovo-G50-30:~$
Et si je désinstallais tout ce qui est dans home/fred pour le réinstaller dans usr/bin ?
Hors ligne
#21 Le 19/09/2017, à 09:20
- pingouinux
Re : Python ModuleNotFoundError RÉSOLU
Comment as-tu installé ce qui se trouve dans /home/fred/miniconda3/bin/ ?
Si tu lances Pyzo à partir d'un terminal, tu peux essayer de lancer d'abord cette commande :
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
La modification du PATH n'affectera que ce terminal.
Hors ligne
#22 Le 19/09/2017, à 09:28
- BUTZ
Re : Python ModuleNotFoundError RÉSOLU
J'ai installé depuis ici : http://www.pyzo.org/start.html.
J'ai fais ce que tu proposais :
fred@fred-Lenovo-G50-30:~$ export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
fred@fred-Lenovo-G50-30:~$ pyzo
Started our command server
loading qt French: ok
loading pyzo French: ok
Malheureusement, ça ne change rien lors de l'exécution du script en question.
Il faut que j'y aille ; je ne reviendrai que ce soir.
Merci de ta patience en tout cas.
Hors ligne
#23 Le 20/09/2017, à 16:00
- BUTZ
Re : Python ModuleNotFoundError RÉSOLU
Bon ben j'ai résolu le problème d'une façon qui n'est pas très propre mais rapide et efficace, sur une suggestion de mon copain Laurent.
Dans le menu Pyzo>Shell>configurationdeshells, je force Pyzo à utiliser le Python 3 qui est dans le dossier usr/bin au lieu de celui qui est dans home/fred.
Si ça peut servir à d'autres...
@+
FRED
Hors ligne