Contenu | Rechercher | Menus

Annonce

Si vous avez des soucis pour rester connecté, déconnectez-vous puis reconnectez-vous depuis ce lien en cochant la case
Me connecter automatiquement lors de mes prochaines visites.

À propos de l'équipe du forum.

#1 Le 08/05/2025, à 20:22

Jtomoise

Problème avec Python et matplotlib [RÉSOLU]

Bonjour
une quinzaine que je rame avec :

$ ./sincos.py
Traceback (most recent call last):
  File "/home/jean-marc/Old-Documents/Python/./sincos.py", line 4, in <module>
    import matplotlib.pyplot as plt
  File "/home/jean-marc/Old-Documents/Python/matplotlib.py", line 1, in <module>
    import matplotlib.pyplot as plt
ModuleNotFoundError: No module named 'matplotlib.pyplot'; 'matplotlib' is not a package

Pour rappel : A priori Python est installé d'office avec la version 24.04.2 LTS... (??????)
Cordialement

Dernière modification par Jtomoise (Le 12/05/2025, à 21:56)

Hors ligne

#2 Le 08/05/2025, à 20:56

xubu1957

Re : Problème avec Python et matplotlib [RÉSOLU]

Bonjour,

Peux-tu donner le retour de ces commandes :

ls -l /usr/bin/python*
dpkg -l | grep matplotlib

?

Pompé dans Python ModuleNotFoundError RÉSOLU


Conseils pour les nouveaux demandeurs et pas qu'eux
Important : Pensez à passer vos sujets en [Réso|u] lorsque ceux-ci le sont, au début du titre en cliquant sur Modifier sous le premier message, et un bref récapitulatif de la solution à la fin de celui-ci. Merci.                   Membre de Linux-Azur

Hors ligne

#3 Le 09/05/2025, à 08:44

Jtomoise

Re : Problème avec Python et matplotlib [RÉSOLU]

$ ls -l /usr/bin/python*
lrwxrwxrwx 1 root root       7 juin  13  2023 /usr/bin/python -> python3
lrwxrwxrwx 1 root root      10 août   7  2024 /usr/bin/python3 -> python3.12
-rwxr-xr-x 1 root root 8019136 févr.  4 15:48 /usr/bin/python3.12
lrwxrwxrwx 1 root root      34 févr.  4 15:48 /usr/bin/python3.12-config -> x86_64-linux-gnu-python3.12-config
lrwxrwxrwx 1 root root      17 août   7  2024 /usr/bin/python3-config -> python3.12-config
lrwxrwxrwx 1 root root      58 févr. 14  2024 /usr/bin/pythontex -> ../share/texlive/texmf-dist/scripts/pythontex/pythontex.py
$ dpkg -l | grep matplotlib
ii  python-matplotlib-data                        3.6.3-1ubuntu5                           all          Python based plotting system (data package)
ii  python3-matplotlib                            3.6.3-1ubuntu5                           amd64        Python based plotting system in a style similar to Matlab (Python 3)

En espérant avoir répondu à tes attentes...

Hors ligne

#4 Le 09/05/2025, à 09:06

xubu1957

Re : Problème avec Python et matplotlib [RÉSOLU]

Bonjour,

Fournis les retours de :

sudo apt update

et d'éventuels paquets cassés :

dpkg -l | grep -v ^ii

Conseils pour les nouveaux demandeurs et pas qu'eux
Important : Pensez à passer vos sujets en [Réso|u] lorsque ceux-ci le sont, au début du titre en cliquant sur Modifier sous le premier message, et un bref récapitulatif de la solution à la fin de celui-ci. Merci.                   Membre de Linux-Azur

Hors ligne

#5 Le 09/05/2025, à 09:28

Jtomoise

Re : Problème avec Python et matplotlib [RÉSOLU]

$ sudo apt update
[sudo] Mot de passe de jean-marc : 
Réception de :1 http://security.ubuntu.com/ubuntu noble-security InRelease [126 kB]
Atteint :2 http://fr.archive.ubuntu.com/ubuntu noble InRelease                 
Réception de :3 http://fr.archive.ubuntu.com/ubuntu noble-updates InRelease [126 kB]
Réception de :4 http://fr.archive.ubuntu.com/ubuntu noble-backports InRelease [126 kB]
Réception de :5 https://esm.ubuntu.com/apps/ubuntu noble-apps-updates InRelease [7480 B]
Réception de :6 https://esm.ubuntu.com/apps/ubuntu noble-apps-security InRelease [7595 B]
Réception de :7 https://esm.ubuntu.com/infra/ubuntu noble-infra-updates InRelease [7473 B]
Réception de :8 https://esm.ubuntu.com/infra/ubuntu noble-infra-security InRelease [7474 B]
Réception de :9 http://security.ubuntu.com/ubuntu noble-security/main amd64 Packages [820 kB]
Réception de :10 http://fr.archive.ubuntu.com/ubuntu noble-updates/main amd64 Packages [1067 kB]
Réception de :11 http://security.ubuntu.com/ubuntu noble-security/main i386 Packages [278 kB]
Réception de :12 http://security.ubuntu.com/ubuntu noble-security/main amd64 Components [21,6 kB]
Réception de :13 http://security.ubuntu.com/ubuntu noble-security/restricted amd64 Components [212 B]
Réception de :14 http://security.ubuntu.com/ubuntu noble-security/universe i386 Packages [517 kB]
Réception de :15 http://security.ubuntu.com/ubuntu noble-security/universe amd64 Packages [836 kB]
Réception de :16 http://security.ubuntu.com/ubuntu noble-security/universe Translation-en [182 kB]
Réception de :17 http://fr.archive.ubuntu.com/ubuntu noble-updates/main i386 Packages [466 kB]
Réception de :18 http://security.ubuntu.com/ubuntu noble-security/universe amd64 Components [52,3 kB]
Réception de :19 http://security.ubuntu.com/ubuntu noble-security/multiverse amd64 Components [212 B]
Réception de :20 http://fr.archive.ubuntu.com/ubuntu noble-updates/main Translation-en [229 kB]
Réception de :21 http://fr.archive.ubuntu.com/ubuntu noble-updates/main amd64 Components [161 kB]
Réception de :22 http://fr.archive.ubuntu.com/ubuntu noble-updates/restricted amd64 Components [212 B]
Réception de :23 http://fr.archive.ubuntu.com/ubuntu noble-updates/universe amd64 Packages [1062 kB]
Réception de :24 http://fr.archive.ubuntu.com/ubuntu noble-updates/universe i386 Packages [642 kB]
Réception de :25 http://fr.archive.ubuntu.com/ubuntu noble-updates/universe Translation-en [269 kB]
Réception de :26 http://fr.archive.ubuntu.com/ubuntu noble-updates/universe amd64 Components [376 kB]
Réception de :27 http://fr.archive.ubuntu.com/ubuntu noble-updates/multiverse amd64 Components [940 B]
Réception de :28 http://fr.archive.ubuntu.com/ubuntu noble-backports/main amd64 Components [7096 B]
Réception de :29 http://fr.archive.ubuntu.com/ubuntu noble-backports/restricted amd64 Components [216 B]
Réception de :30 http://fr.archive.ubuntu.com/ubuntu noble-backports/universe amd64 Components [16,4 kB]
Réception de :31 http://fr.archive.ubuntu.com/ubuntu noble-backports/multiverse amd64 Components [212 B]
7414 ko réceptionnés en 2s (3237 ko/s)                                 
Lecture des listes de paquets... Fait
Construction de l'arbre des dépendances... Fait
Lecture des informations d'état... Fait      
65 paquets peuvent être mis à jour. Exécutez « apt list --upgradable » pour les voir.
~$ dpkg -l | grep -v ^ii
Souhait=inconnU/Installé/suppRimé/Purgé/H=à garder
| État=Non/Installé/fichier-Config/dépaqUeté/échec-conFig/H=semi-installé/W=attend-traitement-déclenchements
|/ Err?=(aucune)/besoin Réinstallation (État,Err: majuscule=mauvais)
||/ Nom                                           Version                                  Architecture Description
+++-=============================================-========================================-============-================================================================================
rc  linux-image-6.8.0-45-generic                  6.8.0-45.45                              amd64        Signed kernel image generic
rc  linux-image-6.8.0-47-generic                  6.8.0-47.47                              amd64        Signed kernel image generic
rc  linux-image-6.8.0-48-generic                  6.8.0-48.48                              amd64        Signed kernel image generic
rc  linux-image-6.8.0-49-generic                  6.8.0-49.49                              amd64        Signed kernel image generic
rc  linux-image-6.8.0-50-generic                  6.8.0-50.51                              amd64        Signed kernel image generic
rc  linux-image-6.8.0-51-generic                  6.8.0-51.52                              amd64        Signed kernel image generic
rc  linux-image-6.8.0-52-generic                  6.8.0-52.53                              amd64        Signed kernel image generic
rc  linux-image-6.8.0-53-generic                  6.8.0-53.55                              amd64        Signed kernel image generic
rc  linux-image-6.8.0-54-generic                  6.8.0-54.56                              amd64        Signed kernel image generic
rc  linux-image-6.8.0-55-generic                  6.8.0-55.57                              amd64        Signed kernel image generic
rc  linux-image-6.8.0-56-generic                  6.8.0-56.58+1                            amd64        Signed kernel image generic
rc  linux-image-6.8.0-57-generic                  6.8.0-57.59                              amd64        Signed kernel image generic
rc  linux-modules-6.8.0-45-generic                6.8.0-45.45                              amd64        Linux kernel extra modules for version 6.8.0 on 64 bit x86 SMP
rc  linux-modules-6.8.0-47-generic                6.8.0-47.47                              amd64        Linux kernel extra modules for version 6.8.0 on 64 bit x86 SMP
rc  linux-modules-6.8.0-48-generic                6.8.0-48.48                              amd64        Linux kernel extra modules for version 6.8.0 on 64 bit x86 SMP
rc  linux-modules-6.8.0-49-generic                6.8.0-49.49                              amd64        Linux kernel extra modules for version 6.8.0 on 64 bit x86 SMP
rc  linux-modules-6.8.0-50-generic                6.8.0-50.51                              amd64        Linux kernel extra modules for version 6.8.0 on 64 bit x86 SMP
rc  linux-modules-6.8.0-51-generic                6.8.0-51.52                              amd64        Linux kernel extra modules for version 6.8.0 on 64 bit x86 SMP
rc  linux-modules-6.8.0-52-generic                6.8.0-52.53                              amd64        Linux kernel extra modules for version 6.8.0 on 64 bit x86 SMP
rc  linux-modules-6.8.0-53-generic                6.8.0-53.55                              amd64        Linux kernel extra modules for version 6.8.0 on 64 bit x86 SMP
rc  linux-modules-6.8.0-54-generic                6.8.0-54.56                              amd64        Linux kernel extra modules for version 6.8.0 on 64 bit x86 SMP
rc  linux-modules-6.8.0-55-generic                6.8.0-55.57                              amd64        Linux kernel extra modules for version 6.8.0 on 64 bit x86 SMP
rc  linux-modules-6.8.0-56-generic                6.8.0-56.58                              amd64        Linux kernel extra modules for version 6.8.0 on 64 bit x86 SMP
rc  linux-modules-6.8.0-57-generic                6.8.0-57.59                              amd64        Linux kernel extra modules for version 6.8.0 on 64 bit x86 SMP
rc  linux-modules-extra-6.8.0-45-generic          6.8.0-45.45                              amd64        Linux kernel extra modules for version 6.8.0 on 64 bit x86 SMP
rc  linux-modules-extra-6.8.0-47-generic          6.8.0-47.47                              amd64        Linux kernel extra modules for version 6.8.0 on 64 bit x86 SMP
rc  linux-modules-extra-6.8.0-48-generic          6.8.0-48.48                              amd64        Linux kernel extra modules for version 6.8.0 on 64 bit x86 SMP
rc  linux-modules-extra-6.8.0-49-generic          6.8.0-49.49                              amd64        Linux kernel extra modules for version 6.8.0 on 64 bit x86 SMP
rc  linux-modules-extra-6.8.0-50-generic          6.8.0-50.51                              amd64        Linux kernel extra modules for version 6.8.0 on 64 bit x86 SMP
rc  linux-modules-extra-6.8.0-51-generic          6.8.0-51.52                              amd64        Linux kernel extra modules for version 6.8.0 on 64 bit x86 SMP
rc  linux-modules-extra-6.8.0-52-generic          6.8.0-52.53                              amd64        Linux kernel extra modules for version 6.8.0 on 64 bit x86 SMP
rc  linux-modules-extra-6.8.0-53-generic          6.8.0-53.55                              amd64        Linux kernel extra modules for version 6.8.0 on 64 bit x86 SMP
rc  linux-modules-extra-6.8.0-54-generic          6.8.0-54.56                              amd64        Linux kernel extra modules for version 6.8.0 on 64 bit x86 SMP
rc  linux-modules-extra-6.8.0-55-generic          6.8.0-55.57                              amd64        Linux kernel extra modules for version 6.8.0 on 64 bit x86 SMP
rc  linux-modules-extra-6.8.0-56-generic          6.8.0-56.58                              amd64        Linux kernel extra modules for version 6.8.0 on 64 bit x86 SMP
rc  linux-modules-extra-6.8.0-57-generic          6.8.0-57.59                              amd64        Linux kernel extra modules for version 6.8.0 on 64 bit x86 SMP
rc  linux-modules-nvidia-470-6.8.0-45-generic     6.8.0-45.45+1                            amd64        Linux kernel nvidia modules for version 6.8.0-45
rc  linux-modules-nvidia-470-6.8.0-47-generic     6.8.0-47.47+1                            amd64        Linux kernel nvidia modules for version 6.8.0-47
rc  linux-modules-nvidia-470-6.8.0-48-generic     6.8.0-48.48+1                            amd64        Linux kernel nvidia modules for version 6.8.0-48
rc  linux-modules-nvidia-470-6.8.0-49-generic     6.8.0-49.49+1                            amd64        Linux kernel nvidia modules for version 6.8.0-49
rc  linux-modules-nvidia-470-6.8.0-50-generic     6.8.0-50.51+1                            amd64        Linux kernel nvidia modules for version 6.8.0-50
rc  linux-modules-nvidia-470-6.8.0-51-generic     6.8.0-51.52+1                            amd64        Linux kernel nvidia modules for version 6.8.0-51
rc  linux-modules-nvidia-470-6.8.0-52-generic     6.8.0-52.53                              amd64        Linux kernel nvidia modules for version 6.8.0-52
rc  linux-modules-nvidia-470-6.8.0-53-generic     6.8.0-53.55+1                            amd64        Linux kernel nvidia modules for version 6.8.0-53
rc  linux-modules-nvidia-470-6.8.0-54-generic     6.8.0-54.56                              amd64        Linux kernel nvidia modules for version 6.8.0-54
rc  linux-modules-nvidia-470-6.8.0-55-generic     6.8.0-55.57+1                            amd64        Linux kernel nvidia modules for version 6.8.0-55
rc  linux-modules-nvidia-470-6.8.0-56-generic     6.8.0-56.58+1                            amd64        Linux kernel nvidia modules for version 6.8.0-56
rc  linux-modules-nvidia-470-6.8.0-57-generic     6.8.0-57.59                              amd64        Linux kernel nvidia modules for version 6.8.0-57
rc  linux-objects-nvidia-470-6.8.0-45-generic     6.8.0-45.45+1                            amd64        Linux kernel nvidia modules for version 6.8.0-45 (objects)
rc  linux-objects-nvidia-470-6.8.0-47-generic     6.8.0-47.47+1                            amd64        Linux kernel nvidia modules for version 6.8.0-47 (objects)
rc  linux-objects-nvidia-470-6.8.0-48-generic     6.8.0-48.48+1                            amd64        Linux kernel nvidia modules for version 6.8.0-48 (objects)
rc  linux-objects-nvidia-470-6.8.0-49-generic     6.8.0-49.49+1                            amd64        Linux kernel nvidia modules for version 6.8.0-49 (objects)
rc  linux-objects-nvidia-470-6.8.0-50-generic     6.8.0-50.51+1                            amd64        Linux kernel nvidia modules for version 6.8.0-50 (objects)
rc  linux-objects-nvidia-470-6.8.0-51-generic     6.8.0-51.52+1                            amd64        Linux kernel nvidia modules for version 6.8.0-51 (objects)
rc  linux-objects-nvidia-470-6.8.0-52-generic     6.8.0-52.53                              amd64        Linux kernel nvidia modules for version 6.8.0-52 (objects)
rc  linux-objects-nvidia-470-6.8.0-53-generic     6.8.0-53.55+1                            amd64        Linux kernel nvidia modules for version 6.8.0-53 (objects)
rc  linux-objects-nvidia-470-6.8.0-54-generic     6.8.0-54.56                              amd64        Linux kernel nvidia modules for version 6.8.0-54 (objects)
rc  linux-objects-nvidia-470-6.8.0-55-generic     6.8.0-55.57+1                            amd64        Linux kernel nvidia modules for version 6.8.0-55 (objects)
rc  linux-objects-nvidia-470-6.8.0-56-generic     6.8.0-56.58+1                            amd64        Linux kernel nvidia modules for version 6.8.0-56 (objects)
rc  linux-objects-nvidia-470-6.8.0-57-generic     6.8.0-57.59                              amd64        Linux kernel nvidia modules for ve

Hors ligne

#6 Le 09/05/2025, à 09:37

xubu1957

Re : Problème avec Python et matplotlib [RÉSOLU]

Pour purger les résidus de configuration marqués "rc" :

sudo apt purge ~c

comme expliqué à la machine à café et rajouté dans ce message

65 paquets peuvent être mis à jour.

Montre les mises à jour :

sudo apt full-upgrade

Conseils pour les nouveaux demandeurs et pas qu'eux
Important : Pensez à passer vos sujets en [Réso|u] lorsque ceux-ci le sont, au début du titre en cliquant sur Modifier sous le premier message, et un bref récapitulatif de la solution à la fin de celui-ci. Merci.                   Membre de Linux-Azur

Hors ligne

#7 Le 09/05/2025, à 09:56

toitoinebzh

Re : Problème avec Python et matplotlib [RÉSOLU]

salut

je pense que tu devrais lancer ton script de cette manière

python3 sincos.py

Hors ligne

#8 Le 09/05/2025, à 10:51

Jtomoise

Re : Problème avec Python et matplotlib [RÉSOLU]

$ sudo apt full-upgrade
Lecture des listes de paquets... Fait
Construction de l'arbre des dépendances... Fait
Lecture des informations d'état... Fait      
Calcul de la mise à jour... Fait
Les paquets suivants ont été installés automatiquement et ne sont plus nécessaires :
  libcom-err2:i386 libcrypt1:i386 libssl3t64:i386
Veuillez utiliser « sudo apt autoremove » pour les supprimer.
Les paquets suivants ont été conservés :
  ubuntu-advantage-tools

Quant à lancer le script ainsi :

$ python sincos.py
Traceback (most recent call last):
  File "/home/jean-marc/Old-Documents/Python/sincos.py", line 4, in <module>
    import matplotlib.pyplot as plt
  File "/home/jean-marc/Old-Documents/Python/matplotlib.py", line 1, in <module>
    import matplotlib.pyplot as plt
ModuleNotFoundError: No module named 'matplotlib.pyplot'; 'matplotlib' is not a package

C'est précisément la source du problème.
Un des problèmes ( gedit, plantages, authentification...) depuis que j'ai installé la version 24.04.2 LTS.... sur mes différentes machines.
Bien cordialement

Hors ligne

#9 Le 10/05/2025, à 11:50

toitoinebzh

Re : Problème avec Python et matplotlib [RÉSOLU]

tu as le même résultat avec pytthon3 ?

python3 sincos.py

Hors ligne

#10 Le 10/05/2025, à 12:57

Jtomoise

Re : Problème avec Python et matplotlib [RÉSOLU]

Merci pour ta réponse mais
le problème reste le même. Je l'avais bien envisagé.

~/Old-Documents/Python$ python3 sincos.py
Traceback (most recent call last):
  File "/home/jean-marc/Old-Documents/Python/sincos.py", line 4, in <module>
    import matplotlib.pyplot as plt
  File "/home/jean-marc/Old-Documents/Python/matplotlib.py", line 1, in <module>
    import matplotlib.pyplot as plt
ModuleNotFoundError: No module named 'matplotlib.pyplot'; 'matplotlib' is not a package

Ce qui me conduit à conjecturer que le message :

ModuleNotFoundError: No module named 'matplotlib.pyplot'; 'matplotlib' is not a package

ne doit pas être pris à la lettre. Erreur, il y a, c'est une évidence mais à quel niveau ?????  sad tant la situation est inconsistance a priori.
J'en veux pour preuve le nombre de fois où mon post a été lu et l'absence de solution avérée jusqu'alors pour un problème que j'ai osé qualifié moi-même de "basique" avec en substance Python3 qui ne trouve pas une de ses bibiothèques (matplotlib en l'occurrence) fondamentales.
On est habitué ordinairement dans ce type de problème à incriminer un "problème de droits". Ce que beaucoup parmi nous diagnostiquent plutôt rapidement. Mais là... ????
voici une copie du fichier sincos.py

#!/usr/bin/env python3
# -*-coding:Utf-8 -*

import matplotlib.pyplot as plt
import numpy as np

plt.figure(0)
x = np.arange(0,2*np.pi,0.1)   # start,stop,step
y = np.sin(x)
z = np.cos(x)
plt.plot(x,y,x,z)
plt.legend(['sin(x)', 'cos(x)'])     
plt.show()

Cordialement

Dernière modification par Jtomoise (Le 10/05/2025, à 13:07)

Hors ligne

#11 Le 10/05/2025, à 16:30

toitoinebzh

Re : Problème avec Python et matplotlib [RÉSOLU]

ton script fonctionne bien chez moi, tu n'aurais pas jouer avec les environnements virtuels ?

antoine@talos:~/Bureau$ python3 
Python 3.11.2 (main, Nov 30 2024, 21:22:50) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib
>>> 
antoine@talos:~/Bureau$ python3 -m venv venv
antoine@talos:~/Bureau$ source venv/bin/activate
(venv) antoine@talos:~/Bureau$ python3 
Python 3.11.2 (main, Nov 30 2024, 21:22:50) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'matplotlib'
>>> 
(venv) antoine@talos:~/Bureau$ 

Hors ligne

#12 Le 11/05/2025, à 15:05

Jtomoise

Re : Problème avec Python et matplotlib [RÉSOLU]

Merci mais je ne comprends pas dans on message la signification des différentes lignes de commande affichées.

Et bien sûr ce qui t'autorise à dire que mon script marche bien chez toi...

je ne vois pas, quand et comment tu l'as lancé ?
Au final ,que produit chez toi le plt.show() ?

Enfin, comment aurais-je pu jouer avec le environnements virtuels . De mémoire, il est nécessaire de créer un tel environnement pour "jouer" avec ?

Cordialement

Hors ligne

#13 Le 11/05/2025, à 15:21

iznobe

Re : Problème avec Python et matplotlib [RÉSOLU]

Jtomoise a écrit :

Merci mais je ne comprends pas dans on message la signification des différentes lignes de commande affichées.

Bonjour , les lignes de code montre que dans un environnement virtuel python mal implanté , on obtient la même erreur que toi .

Jtomoise a écrit :

Et bien sûr ce qui t'autorise à dire que mon script marche bien chez toi...
je ne vois pas, quand et comment tu l'as lancé ?
Au final ,que produit chez toi le plt.show() ?

Chez moi aussi , le script sincos.py fonctionne correctement :

iznobe@iznobe-pc:~$ cd Scripts
iznobe@iznobe-pc:~/Scripts$ python3 sincos.py 
iznobe@iznobe-pc:~/Scripts$ 

ce qui donne :
https://ibb.co/PzP7GfL4

https://ibb.co/PzP7GfL4

Et sinon , oui python 3 est installé par défaut avec toutes les versions d' ubuntu , et matplotlib aussi .
j' ai eu juste à lancer ton script pour que cela fonctionne .

Dernière modification par iznobe (Le 11/05/2025, à 15:28)


retour COMPLET et utilisable de commande  |  script montage partitions

MSI Z490A-pro , i7 10700 , 32 GB RAM .

Hors ligne

#14 Le 11/05/2025, à 16:36

Jtomoise

Re : Problème avec Python et matplotlib [RÉSOLU]

Alors que l'équivalent chez moi... donne toujours :

jean-marc@tom-h81m-d2v:~/Old-Documents/Python$ python3 sincos.py
Traceback (most recent call last):
  File "/home/jean-marc/Old-Documents/Python/sincos.py", line 4, in <module>
    import matplotlib.pyplot as plt
  File "/home/jean-marc/Old-Documents/Python/matplotlib.py", line 1, in <module>
    import matplotlib.pyplot as plt
ModuleNotFoundError: No module named 'matplotlib.pyplot'; 'matplotlib' is not a package
jean-marc@tom-h81m-d2v:~/Old-Documents/Python$ 

~/Old-Documents/Python$
étant bien sûr l'équivalent de ton répertoire
~/Scripts$

Le mystère reste entier..

Hors ligne

#15 Le 11/05/2025, à 21:53

toitoinebzh

Re : Problème avec Python et matplotlib [RÉSOLU]

salut

je pense que j'ai trouvé pourquoi tu as un soucis

est ce que tu peux donner le retour de

ls ~/Old-Documents/Python

si tu as un fichier nommé matplotlib.py dans ton dossier renomme le script_matplotlib.py par exemple

Hors ligne

#16 Le 12/05/2025, à 15:03

Jtomoise

Re : Problème avec Python et matplotlib [RÉSOLU]

~/Old-Documents/Python$ ls -l
total 89164
-rw-rw-r-- 1 jean-marc jean-marc      240 janv. 19 21:25 aire-max.py
-rw-rw-r-- 1 jean-marc jean-marc 13420724 oct.   8  2013 apprenez_a_programmer_en_python.pdf
-rw-rw-r-- 1 jean-marc jean-marc  2375019 oct.   8  2013 courspython3.pdf
-rw-rw-r-- 1 jean-marc jean-marc      817 mai    4 09:05 dichotomie.py
-rw-rw-r-- 1 jean-marc jean-marc      381 mai    4 09:35 dichotomie.py.save
-rw-rw-r-- 1 jean-marc jean-marc      593 mai    3 19:13 Echantillonnage.py
-rwxr----- 1 jean-marc jean-marc      305 mai    1 14:37 Essai-Script.py
-rw-rw-r-- 1 jean-marc jean-marc      433 janv. 19 21:06 Ex1-Tkinter.py
-rw-rw-r-- 1 jean-marc jean-marc      431 nov.  18  2012 Ex1-Tkinter.py~
-rw-rw-r-- 1 jean-marc jean-marc      403 nov.  18  2012 Ex2-Tkinter.py
-rw-rw-r-- 1 jean-marc jean-marc      403 nov.  18  2012 Ex2-Tkinter.py~
-rw-rw-r-- 1 jean-marc jean-marc      332 nov.  18  2012 Ex3-Tkinter.py
-rw-rw-r-- 1 jean-marc jean-marc      332 nov.  18  2012 Ex3-Tkinter.py~
-rw-rw-r-- 1 jean-marc jean-marc      335 nov.  18  2012 Ex4-Tkinter.py
-rw-rw-r-- 1 jean-marc jean-marc      335 nov.  18  2012 Ex4-Tkinter.py~
-rw-rw-r-- 1 jean-marc jean-marc      398 nov.  18  2012 Exemple1_Tkinter.py
-rw-rw-r-- 1 jean-marc jean-marc      401 nov.  18  2012 Exemple1_Tkinter.py~
-rw-rw-r-- 1 jean-marc jean-marc      191 nov.  18  2012 Ex-Tkinter.py
-rw-rw-r-- 1 jean-marc jean-marc      191 nov.  18  2012 Ex-Tkinter.py~
-rw-rw-r-- 1 jean-marc jean-marc      215 janv. 19 21:11 fibo.py
-rw-rw-r-- 1 jean-marc jean-marc      563 nov.  18  2012 histogram_demo.py
-rw-rw-r-- 1 jean-marc jean-marc      563 nov.  18  2012 histogram_demo.py~
-rwxrwxr-x 1 jean-marc jean-marc      154 mai    8 13:07 Line-plot.py
-rw-rw-r-- 1 jean-marc jean-marc      274 janv. 19 21:31 mafonction2.py
-rw-rw-r-- 1 jean-marc jean-marc      176 janv. 19 21:38 mafonction.py
-rw-rw-r-- 1 jean-marc jean-marc      244 nov.  18  2012 module1.py
-rw-rw-r-- 1 jean-marc jean-marc       85 janv. 19 21:14 moncul.py
-rw-rw-r-- 1 jean-marc jean-marc 36221888 mai   11 16:09 np
-rw-rw-r-- 1 jean-marc jean-marc  3315900 mai    7 14:45 pathlib
-rw-rw-r-- 1 jean-marc jean-marc 35428194 mai   11 16:11 plt
-rw-rw-r-- 1 jean-marc jean-marc      197 mai    4 09:37 Plus_grand_nombre.py
-rw-rw-r-- 1 jean-marc jean-marc     1037 mai    4 09:01 ppc.py
drwxrwxr-x 2 jean-marc jean-marc     4096 mai   11 21:12 __pycache__
-rw-rw-r-- 1 jean-marc jean-marc   392177 oct.   8  2013 python_tutoriel_fr.pdf
-rw-rw-r-- 1 jean-marc jean-marc      152 mai    7 14:31 script_matplotlib.py
-rwxrwxr-x 1 jean-marc jean-marc      256 mai   11 16:23 sincos.py
-rw-rw-r-- 1 jean-marc jean-marc      187 mai    7 11:46 sin.py
-rw-rw-r-- 1 jean-marc jean-marc      581 nov.  18  2012 surarguments.py

Cela étant, je pense que nous approchons du but.
j'obtiens bien désormais  l'affichage des fonctions définies dans les scripts sincos.py, sin.py ou encore Line-plot.py.. ; en fait des scripts dont l'écriture du code ne présente pas d'erreurs de conception particulières.
Un succès d'affichage que j'avais également obtenu en créant un dossier ./Scripts dans lequel je n'avais copié que ces scripts (ne contenant donc pas le script matplotlib.py incriminable) lancés bien sûr avec python3.
Avancée que j'allais vous soumettre et que tu as a priori devancée et renforcée en précisant la cause "originelle" du problème.

Merci à toutes et à tous pour votre soutien.
PS. J'attends quelque temps avant d'afficher notre indispensable protocolaire [RÉSOLU] .

Hors ligne

#17 Le 12/05/2025, à 18:36

toitoinebzh

Re : Problème avec Python et matplotlib [RÉSOLU]

merci pour ton retour sur le sujet

en fait quand tu fais "import matplotlib", python va d'abord chercher les fonctions dans ton fichier matplotlib.py et si il ne le trouve pas il cherche dans les packages installés dans ubuntu

je te recommande donc de ne pas nommer tes scripts avec un nom de librairie que tu veux utiliser

Hors ligne

#18 Le 12/05/2025, à 21:55

Jtomoise

Re : Problème avec Python et matplotlib [RÉSOLU]

Merci, je prends note.
Cordilement

Hors ligne