Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using buildozer and beautifulsoup
#1
Hi everyone. 
I have a program that works fine on my PC but when I try to use buildozer to get it on to my tablet or phone, it installs ok but doesn't load when you run it.  Looking at the logcat, it says:  
Error:
ImportError: cannot import name _htmlparser 
So I have had a look around and a few others have had this problem and have solved it.  
However, as I am very much a newbie at coding at the moment, I can't seem to see how to solve it exactly and so wanted to see if anyone could help me work out the solution..
The stackoverflow thread is here:  http://stackoverflow.com/questions/23952...on-android

The code that I'm trying to run that apparently fixed the issue is here:

import imp
import sys

class ImportBlocker(object):

    def __init__(self, *args):
        self.black_list = args

    def find_module(self, name, path=None):
        if name in self.black_list:
            return self

        return None

    def load_module(self, name):
        module = imp.new_module(name)
        module.__all__ = [] # Necessary because of how bs4 inspects the module

        return module

sys.meta_path = [ImportBlocker('bs4.builder._htmlparser')]
from bs4 import BeautifulSoup
However this for me is saying..      
Error:
from bs4 import BeautifulSoup ImportError: No module named 'bs4'
 
Without the above code.. there is no problem importing the bs4 module.  

Am I missing something obvious?

Many thanks for any guidance!  Greatly appreciate it.
Reply
#2
try this;
from BeautifulSoup import BeautifulSoup
Reply
#3
Import the bs4 module along with the other import statement.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#4
If I change to "from BeautifulSoup import BeautifulSoup" it says: ImportError: No module named 'BeautifulSoup'

If I import the bs4 with the other import, weirdly it then says that the next module import underneath is not found.. "No module named 'xmltodict" or if I put after all imports.. and above the kivy classes, it says "ImportError: No module named 'kivy.core.window'" It's almost like it's just blocking the very next thing regardless. I thought that its aim was to block the html parser only?

If there's another library I could use, I don't mind redoing it again... perhaps feedparser?
Reply
#5
lxml?
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply


Forum Jump:

User Panel Messages

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