AttributeError: 'HTMLParser' object has no attribute 'unescape'
eyalroz opened this issue · 4 comments
I'm trying to use mdv on an old(ish) distribution, with Python 2.7.5 . When it runs, I get:
Traceback (most recent call last):
File "/home/lh156516/.local/bin/mdv", line 33, in <module>
sys.exit(load_entry_point('mdv==1.7.4', 'console_scripts', 'mdv')())
File "/home/lh156516/.local/lib/python3.9/site-packages/mdv/markdownviewer.py", line 1657, in run
print(main(**kw) if PY3 else str(main(**kw)))
File "/home/lh156516/.local/lib/python3.9/site-packages/mdv/markdownviewer.py", line 1375, in main
the_html = MD.convert(md)
File "/usr/local/lib/python3.9/site-packages/markdown/core.py", line 268, in convert
newRoot = treeprocessor.run(root)
File "/home/lh156516/.local/lib/python3.9/site-packages/mdv/markdownviewer.py", line 1150, in run
formatter(doc, out)
File "/home/lh156516/.local/lib/python3.9/site-packages/mdv/markdownviewer.py", line 1145, in formatter
formatter(c, out, hir + 1, parent=el)
File "/home/lh156516/.local/lib/python3.9/site-packages/mdv/markdownviewer.py", line 970, in formatter
t = html_parser.unescape(t)
AttributeError: 'HTMLParser' object has no attribute 'unescape'
If you don't support this Python version, the pip install should fail, or the script should say so. If you do support this version of python - then this is a bug.
This is an issue with Python 3.9; if you read the trace, you can see it right in the path. HTMLParser has changes in 3.9 that break mdv
. If you're on Ubuntu, chances are the system installation of Python 3 is a little bit older, and should still work. Here's how I fixed this:
cat $(which mdv)
will display the script that launches mdv
. Take note of the first line, which indicates the path to the version of Python it's running in. If it already says #!/usr/bin/python3
, then this fix won't work for you. If it says something else, it's not using your system Python but one that is installed somewhere else. which python3
should give you the same path. To fix this, we want to remove mdv
from this version of Python and install it as a package for your system Python instead. If the two Python paths we saw matched, go ahead and remove mdv
with python3 -m pip uninstall mdv
.
Now, we want to install mdv
to our system Python 3. Make sure you have the correct packages installed:
sudo apt-get install python3 python3-pip
Finally, we can install mdv
:
/usr/bin/python3 -m pip install mdv
You'll probably need to start a new terminal session to see the change, but now if you do cat $(which mdv)
it should show /usr/bin/python3
as the executable.
Here's how I fixed this:
You're suggesting that users should do something. I'm claiming that you should do something. If you require Python 3.9, then, when starting up - check the Python version, and if it's earlier, fail informatively.
Also, I'm stuck on an old distribution and can't play with the Python installation.
@austinthresher Wasn't this issue fixed with this commit ?
Moreover, this issue is a duplicate of #97 ...
@austinthresher: this commit solves the issue. Any chance you could tag a new release? It's been a while since the last release 😄