I am trying to to following:
from bs4 import BeautifulSoup
and got the error
Traceback (most recent call last):
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/admin/__init__.py", line 355, in post
exec(compiled_code, globals())
File "<string>", line 1, in <module>
ImportError: No module named bs4
How can I use it with Google App Engine runtime 2.7
?
Update
My project structure looks like
flask-appengine-template/
docs/
licenses/
src/
application/
static/
templates/
models.py
settings.py
urls.py
views.py
libs/
bs4/
app.yaml
src.py
I am using this template from here
Since parent of app.yaml
is src
, I added a file src.py
and added two lines there.
I still see the same error
ImportError: No module named bs4
However, my project name as per app.yaml
is flaskonappengine
Please tell me what is I am still doing wrong?
If you want to use 3rd party libraries that are not included this list, then you'll have to add them manually.
In order to include manually any other library you have to have them inside the directory where the app.yaml
lives. So for example if you have the following structure:
hello
├── libs
│ └── bs4
├── hello.py
└── app.yaml
then in your hello.py
you have to put these two lines in the beginning of the file:
import sys
sys.path.insert(0, 'libs')
After doing that you'll be able to use any 3rd party library that you're going to put in that libs
directory. For example:
from bs4 import BeautifulSoup
Since you're using that framework, rollback your changes and use the same pattern as they are using for flask or werkzeug or other 3rd party libraries. Just put the bs4 in the src directory and try to include it normally.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With