Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python error: module 'html5lib.treebuilders' has no attribute '_base' #316

Closed
windonsky opened this issue Sep 23, 2017 · 19 comments
Closed

Comments

@windonsky
Copy link

windonsky commented Sep 23, 2017

sigil cannot run. ( KDEneon X64 based on ubuntu16.04lts)

Traceback (most recent call last):

  File "/usr/share/sigil/python3lib/xmlprocessor.py", line 5, in <module>
    from sigil_bs4 import BeautifulSoup

  File "/usr/share/sigil/plugin_launchers/python/sigil_bs4/__init__.py", line 48, in <module>
    from .builder import builder_registry, ParserRejectedMarkup

  File "/usr/share/sigil/plugin_launchers/python/sigil_bs4/builder/__init__.py", line 328, in <module>
    from . import _html5lib

  File "/usr/share/sigil/plugin_launchers/python/sigil_bs4/builder/_html5lib.py", line 86, in <module>
    class TreeBuilderForHtml5lib(html5lib.treebuilders._base.TreeBuilder):

AttributeError: module 'html5lib.treebuilders' has no attribute '_base'

check the dir /html5lib/treebuilders :

:/usr/local/lib/python3.5/dist-packages/html5lib/treebuilders$>ls
_base.py  base.py  dom.py  etree_lxml.py  etree.py  __init__.py  __pycache__

the module file "base.py" exists in html5lib, but the "_base.py" not exists.
it does not work that copying base.py to _base.py。

@kevinhendricks
Copy link
Contributor

Is this your own build? If so on what distribution? Your "ls" command does in fact show _base.py in your listing of files. It comes just before base.py, which directly contradicts what you are saying.

@windonsky
Copy link
Author

windonsky commented Sep 23, 2017

  1. all python packages in my os are installed by default or pip/pip3.
  2. the sigil is installed by order "sudo apt install sigil" from ubuntu's archive.
  3. In the dir "/usr/local/lib/python3.5/dist-packages/html5lib/treebuilders":
    file "base.py" exists by default;
    file "_base.py" does not exist by default; it is copied from "base.py"; this method takes no effect.

@windonsky
Copy link
Author

I have solved the problem:

  1. /usr/share/sigil/plugin_launchers/python/sigil_bs4/builder$>sudo emacs _html5lib.py
  2. replace the string "_base" by "base" in "_html5lib.py "
    now the sigil works.

@dougmassay
Copy link
Contributor

It's an issue with the newest version of html5lib. The latest version of upstream bs4 accommodates it. We may have to look into incorporating upstream bs4 changes in our sigil_bs4.

https://bugs.launchpad.net/beautifulsoup/+bug/1603299

Possibly a simple try/except clause in our sigil_bs4 to work with all html5lib versions.

A temporary workaround for Linux users who installed html5lib with pip3 would be to force downgrade html5lib to an earlier version with pip3

We'll run into the same problem if we upgrade html5lib to the latest version in our Windows/Mac bundled Python.

@dougmassay
Copy link
Contributor

dougmassay commented Sep 23, 2017

Actually, our version of sigil_bs4 accommodates this already. I'd suspect upstream Ubuntu of changing something, but they'd be more prone to replace sigil_bs4 entirely than leave it in and break it. Are you certain you didn't try to replace sigil_bs4?

EDIT:

Yes: from your first post, this is most definitely not from the official sigil_bs4/builder/_html5lib.py source

File "/usr/share/sigil/plugin_launchers/python/sigil_bs4/builder/_html5lib.py", line 86, in
class TreeBuilderForHtml5lib(html5lib.treebuilders._base.TreeBuilder):

Someone upstream has either built from faulty source, or you've altered the contents of sigil_bs4/ after installing.

@dougmassay
Copy link
Contributor

I've confirmed that your error message does not align with the code/files in sigil_bs4/ that is being delivered with the Sigil binary package from the standard Ubuntu 16.04 software repositories.

Closing this issue as it appears to be a self-inflicted problem.

@dougmassay
Copy link
Contributor

dougmassay commented Sep 23, 2017

Apologies. The _html5lib.py IS broken in the older version of Sigil (v0.9.5) being provided by the 16.04 repositories (beyond a certain version of the html5lib). However ...using the standard Ubuntu repository-provided html5lib (apt-get install python3-html5lib) should ensure you don't experience this issue.

Recommendation:

  • restore original sigil_bs4/ contents
  • remove html5lib installed with pip3: pip3 uninstall html5lib
  • install the standard repo html5lib: sudo apt-get install python3-html5lib

If the repo-provided htmllib is newer then what Sigil v0.9.5 can use, then I recommend installing Sigil v0.9.8 from ppa:mapreri/sigil PPA.

@dougmassay dougmassay reopened this Sep 23, 2017
@dougmassay
Copy link
Contributor

Closing this, as it's fixed in the latest version of Sigil

@JuneFreer
Copy link

I have solved the problem:

  1. /usr/share/sigil/plugin_launchers/python/sigil_bs4/builder$>sudo emacs _html5lib.py
  2. replace the string "_base" by "base" in "_html5lib.py "
    now the sigil works.

I have solved this problem by using your method, thank you!

@kevinhendricks
Copy link
Contributor

This should not be needed with any recent version of Sigil. What Sigil version are you using?

@JuneFreer
Copy link

This should not be needed with any recent version of Sigil. What Sigil version are you using?

actually I did not use Sigil, and I don't know what is Sigil, I just met a similar problem.

@kevinhendricks
Copy link
Contributor

And commented about it in Sigil github issues on a bug that was fixed over 2 years ago.

@eli-schwartz
Copy link
Contributor

I wonder how you could possibly solve your problem by editing the file /usr/share/sigil/plugin_launchers/python/sigil_bs4/builder/_html5lib.py if you don't use sigil....

Whatever software you do use that is self-declared as totally unrelated to this repository has quite possibly been subtly broken by API-level incompatibilities, though, which you are papering over by editing a file you don't understand, from a project you don't use. If you had any idea what you were doing, you would know this...

/me headdesk 🤦🤦🤦

@JuneFreer
Copy link

I wonder how you could possibly solve your problem by editing the file /usr/share/sigil/plugin_launchers/python/sigil_bs4/builder/_html5lib.py if you don't use sigil....

Whatever software you do use that is self-declared as totally unrelated to this repository has quite possibly been subtly broken by API-level incompatibilities, though, which you are papering over by editing a file you don't understand, from a project you don't use. If you had any idea what you were doing, you would know this...

/me headdesk 🤦🤦🤦

Thank you for your reply and guide. I just searched that Sigil is an open source software. I met this problem because I was learning how to use the BeautifulSoup, the _html5lib.py is a file that inside the BeautifulSoup folders, and I just got the same Traceback message as this issue, so I tried to use this method to solve it, even though I don't very understand the principles. I'm learning it now.

@JuneFreer
Copy link

I wonder how you could possibly solve your problem by editing the file /usr/share/sigil/plugin_launchers/python/sigil_bs4/builder/_html5lib.py if you don't use sigil....

Whatever software you do use that is self-declared as totally unrelated to this repository has quite possibly been subtly broken by API-level incompatibilities, though, which you are papering over by editing a file you don't understand, from a project you don't use. If you had any idea what you were doing, you would know this...

/me headdesk 🤦🤦🤦

and if my reply is not permitted in this issue, I will delete it

@saranvdev
Copy link

I have solved the problem:

1. /usr/share/sigil/plugin_launchers/python/sigil_bs4/builder$>sudo emacs _html5lib.py

2. replace the string "_base" by "base" in "_html5lib.py "
   now the sigil works.

Thank you very much, this fixed the error perfectly.

@eli-schwartz
Copy link
Contributor

@saranvdev

This should not be needed with any recent version of Sigil. What Sigil version are you using?

@saranvdev
Copy link

saranvdev commented Jun 24, 2020

I have no idea what Sigil is to be honest, but it was still helpful for another app (Anki).

@eli-schwartz
Copy link
Contributor

eli-schwartz commented Jun 24, 2020

Again???

Why are people posting about non-Sigil related stuff here. The problem is a fundamental API problem. You need to use the correct versions of beautifulsoup and html5lib in your application. If you do, things work. If you don't, things break.

After careful evaluation of the versions involved, the Sigil developers determined it was safe to rename one specific version of their beautifulsoup fork without ill effects. You cannot just rename things willy-nilly, it may not work or it may seem to work but then break in subtle ways.

Your other program has a good chance of being broken in subtle ways now. It should be fixed properly... Please consult the upstream developers of your other program.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants