LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   ModuleNotFoundError: No module named 'html.entities'; 'html' is not a package (python3 error) (https://www.linuxquestions.org/questions/linux-software-2/modulenotfounderror-no-module-named-html-entities%3B-html-is-not-a-package-python3-error-4175695341/)

kaz2100 05-20-2021 12:43 AM

ModuleNotFoundError: No module named 'html.entities'; 'html' is not a package (python3 error)
 
Hya,

Situation While converting python2 script to python3, I ran into this error.
Code:

ModuleNotFoundError: No module named 'html.entities'; 'html' is not a package
Steps to this error: With a good python2 script, it is converted to by 2to3, and minor modification (from . import foo -> import foo)
System: Debian amd64, python 3.9.1

Troubleshooting
Related 2to3 log follows:
Code:

-import htmlentitydefs
+import html.entities

-    for name, char in htmlentitydefs.entitydefs.items():
+    for name, char in list(html.entities.entitydefs.items()):

So, it may be related to 2to3. Errer occured at the import statement. No additional message at the end of diff output.

1.1 Several html.py files exist under /usr/lib/python3 ( /usr/lib/python3/dist-packages/IPython/html.py, /usr/lib/python3/dist-packages/humanfriendly/terminal/html.py, /usr/lib/python3/dist-packages/wx/html.py, /usr/lib/python3/dist-packages/pygments/formatters/html.py
/usr/lib/python3/dist-packages/pygments/lexers/html.py, /usr/lib/python3/dist-packages/prompt_toolkit/formatted_text/html.py)
1.2 It does not look like there is class/function/variable named entities. (I am not familiar with modulename.itemname. Tutorial section 6.1 says it is ok.)
2. This site mentions about this error.

I am a kind of lost at this moment. If the former scenario, the error message is not quite correct. If the latter, it is 5 years old bug/issue. I need to figure out what I am missing.

Question Does anybody know how to solve this?

Closing remark Have a happy penguin!

Any clue will be appreciated.

kaz2100 05-20-2021 01:59 AM

Hya,

self reply, not solved yet.

Under interactive mode
Code:

>>> import html.entities
>>>

It works. Is there anything like import order/incompatibility problem?

cheers

kaz2100 05-24-2021 09:06 PM

self reply.

It turned out to be that this problem is same as this one.

cheers

pan64 05-25-2021 12:48 AM

different python versions may (and should) have different PYTHONPATH settings and you need to install your modules using the appropriate one (including python2.X.Y and any python3.X.Y)
I guess mixing it is not a good idea (=using packages from another python version)
also python2to3 will not install modules for you (but modules installed for python2 will not be available any more).


All times are GMT -5. The time now is 04:50 PM.