Python Forum
Unable to find an existing module
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Unable to find an existing module
#1
Hi everybody

I coded this script
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import io
import xml.etree.ElementTree as et

def affiche(noeud, niveau):
	html='<'+noeud.tag
	if niveau > 0:
		html='\t' * int(niveau) + html
	liste=[html]
	for attr in noeud.items():
		x = attr[0] + "='" + attr[1] + "'"
		liste.append(x)
	code_html=' '.join(liste)+">"
	texte_inclus=noeud.text
	try:
		texte_inclus=texte_inclus[:len(texte_inclus)-2]
	except:
		texte_inclus=""
	if len(texte_inclus)>0:
		code_html=code_html+texte_inclus
	print (code_html)
	for fils in noeud.findall('./*'):
		affiche(fils,niveau+1)
	html='</'+noeud.tag+">"
	if niveau > 0:
		html='\t' * int(niveau) + html
	print(html)
	return True
fichier='/home/grec/dictionnaires/bailly/sommaire.xhtml'
racine=et.parse(fichier).getroot()
affiche(racine,0)
When I enter a command to execute it, I receive an error
Error:
remi@remi-Vostro-3550:~$ python '/home/remi/Documents/programmation/python/affiche.py' Traceback (most recent call last): File "/home/remi/Documents/programmation/python/affiche.py", line 5, in <module> import xml.etree.ElementTree as et File "/home/remi/Documents/psilos/programmation/python/xml.py", line 3, in <module> import sys, io, xml.etree.ElementTree as et ModuleNotFoundError: No module named 'xml.etree'; 'xml' is not a package Error in sys.excepthook: Traceback (most recent call last): File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook from apport.fileutils import likely_packaged, get_recent_crashes File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in <module> from apport.report import Report File "/usr/lib/python3/dist-packages/apport/report.py", line 15, in <module> import xml.dom, xml.dom.minidom File "/home/remi/Documents/psilos/programmation/python/xml.py", line 3, in <module> import sys, io, xml.etree.ElementTree as et ModuleNotFoundError: No module named 'xml.etree'; 'xml' is not a package Original exception was: Traceback (most recent call last): File "/home/remi/Documents/programmation/python/affiche.py", line 5, in <module> import xml.etree.ElementTree as et File "/home/remi/Documents/psilos/programmation/python/xml.py", line 3, in <module> import sys, io, xml.etree.ElementTree as et ModuleNotFoundError: No module named 'xml.etree'; 'xml' is not a package remi@remi-Vostro-3550:~$
However, when I type the «import» command, Python finds xml
remi@remi-Vostro-3550:~$ python
Python 3.8.0 (default, Oct 28 2019, 16:14:01) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> import io
>>> import xml.etree.ElementTree as et
>>> sys.path[0]='/home/remi/Documents/programmation/python'
>>> import affiche
<{http://www.w3.org/1999/xhtml}html>
	<{http://www.w3.org/1999/xhtml}head>
		<{http://www.w3.org/1999/xhtml}meta charset='UTF-8'>
		</{http://www.w3.org/1999/xhtml}meta>
		<{http://www.w3.org/1999/xhtml}link rel='stylesheet' type='text/css' href='file:///home/grec/Textes/textes_xml.css'>
		</{http://www.w3.org/1999/xhtml}link>
		<{http://www.w3.org/1999/xhtml}title>Sommaire du bail
		</{http://www.w3.org/1999/xhtml}title>
	</{http://www.w3.org/1999/xhtml}head>
	<{http://www.w3.org/1999/xhtml}body lang='fr-FR' dir='ltr'>
Thank you to anyone who will explain me what's going wrong.

Arbiel
Reply
#2
by any chance, do you have xml.py file?

You have xml.py file at /home/remi/Documents/psilos/programmation/python/xml.py
rename it to something else
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
Hi buran

You are right.

Thank you.

Arbiel
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Pip lists the module but python does not find it Dato 2 1,232 Apr-13-2023, 06:40 AM
Last Post: Dato
  unable to find module in su mode? korenron 2 1,875 Jan-10-2021, 07:41 PM
Last Post: Gribouillis
  Cannot find module 'torch' ErnestTBass 6 3,542 Oct-13-2020, 05:33 PM
Last Post: ErnestTBass
  Unable to install module rrowhe4d 1 2,252 Oct-13-2020, 10:20 AM
Last Post: Larz60+
  Unable to understand a statement in an existing code ateestructural 1 2,191 Aug-01-2020, 09:38 PM
Last Post: deanhystad
  how to find module in installed packages keuninkske 3 3,151 May-09-2020, 10:21 PM
Last Post: keuninkske
  Unable to import my own module ThePhantom 3 2,670 May-01-2020, 01:30 AM
Last Post: menator01
  Unable to write to excel - Using openpyxl module starstud 2 4,381 Feb-05-2020, 03:53 AM
Last Post: starstud
  Pycharm Cannot Find Pygame Module Myang123 2 5,926 Aug-07-2019, 01:26 AM
Last Post: Myang123
  How to find functions or methods in a module? deepakdeshp 8 4,170 May-23-2019, 09:36 AM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020