pip install with --no-cache-dir and --target

I'm trying to make an AWS lambda function that will run a python script and it has to use python2.7 (because I can't make it work with python3). I am trying to put together a dependency package for my script that includes beautiful soup but I keep running into the error message:

ImportError: No module named html.entities

I've found the source of the error ( - this module was renamed in the switch from 2 to 3) and I found a solution that will make it run without this error on my computer. If I just run pip install --upgrade --no-cache-dir beautifulsoup4, then I can run python2.7 master.py and it works without error. But the problem comes when I try to create this dependency package. I run pip install --upgrade --no-cache-dir beautifulsoup4 --target . and the packages I want show up in the directory, but then when I run the script again it gets the same error as before:

/home/user/.../tempStorage/bs4/element.py:16: UserWarning: The soupsieve package is not installed. CSS selectors cannot be used. 'The soupsieve package is not installed. CSS selectors cannot be used.'
Traceback (most recent call last): File "master.py", line 10, in <module> from bs4 import BeautifulSoup File "/home/user/.../tempStorage/bs4/__init__.py", line 34, in <module> from .builder import builder_registry, ParserRejectedMarkup File "/home/user/.../tempStorage/bs4/builder/__init__.py", line 7, in <module> from bs4.element import ( File "/home/user/.../tempStorage/bs4/element.py", line 19, in <module> from bs4.dammit import EntitySubstitution File "/home/user/.../tempStorage/bs4/dammit.py", line 13, in <module> from html.entities import codepoint2name
ImportError: No module named html.entities

It seems that the difference is that this time it is using the dependencies installed to the directory it is in rather than the ones somewhere else on my machine and unfortunately, it's the ones in this directory that I need to be able to work with. Any help would be appreciated.

EDIT:

A little more info. When I run python2.7 -c "import bs4 ; print(bs4.__version__)" from the directory where I put the dependency packages (with the --target command) I get

bs4/element.py:16: UserWarning: The soupsieve package is not installed. CSS selectors cannot be used. 'The soupsieve package is not installed. CSS selectors cannot be used.'
Traceback (most recent call last): File "<string>", line 1, in <module> File "bs4/__init__.py", line 34, in <module> from .builder import builder_registry, ParserRejectedMarkup File "bs4/builder/__init__.py", line 7, in <module> from bs4.element import ( File "bs4/element.py", line 19, in <module> from bs4.dammit import EntitySubstitution File "bs4/dammit.py", line 13, in <module> from html.entities import codepoint2name
ImportError: No module named html.entities

and when I run the same command from a different directory (I just went to cd .. in this case) I get

4.4.1

Reset to default

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like