I installed beautifulsoup4 in my project's directory, using requirment.txt :
requests==2.26.0 beautifulsoup4==4.9.3 html-parser
pip3 install -r requirement.txt --target='local_lib'
and I get this error when trying to import and run:
from local_lib.bs4 import BeautifulSoup
soup = Beautifulsoup(html, 'html.parser')
local_lib.bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested: html-parser. Do you need to install a parser library?
It works when I tried to import from bs4, not local_lib.bs4. However, I want to use only local_lib directory for modules.
Why I get this error for my local_lib and How can I fix it?
You cannot do it. When do import between its own modules/packages Beautifulsoup4 uses absolute import. For example:
https://bazaar.launchpad.net/~leonardr/beautifulsoup/bs4/view/604/bs4/builder/__init__.py#L7
from bs4.element import …
I.e., bs4
is required to be a top-level package, it cannot be a subpackage. To make it a subpackage you should rewrite the whole source code and make all import relative. Similar to this pull-request to my project Cheetah3 sent with the similar reason: "This makes it possible to embed Cheetah in other packages…"