15

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?

daydreamer
  • 87,243
  • 191
  • 450
  • 722
  • have you added the `bs4` module inside app's folder? BeautifulSoup is not included as a supported library. it is necessary to load it with the application. – Gianni Di Noia Feb 01 '13 at 01:55
  • do I have do do this with any other library which is not part of GAE? – daydreamer Feb 01 '13 at 01:59
  • except this https://developers.google.com/appengine/docs/python/tools/libraries27, yes. – Gianni Di Noia Feb 01 '13 at 02:20
  • you can go through http://www.crummy.com/software/BeautifulSoup/bs4/doc/#installing-beautiful-soup – kiriloff Feb 01 '13 at 03:08
  • 2
    GAE support only [Pure Python Modules](https://developers.google.com/appengine/docs/python/#Python_Pure_Python). The bs4 is not pure bcos its some parts were written in C. But, its old version was written purely in Python. So, You just download [BeautifulSoup 3.2.1](https://pypi.python.org/pypi/BeautifulSoup) then extract the BeautifulSoup.py file from it. – Balakrishnan Sep 08 '13 at 06:01

1 Answers1

33

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

Update

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.

Lipis
  • 21,388
  • 20
  • 94
  • 121
  • Thanks, I tried and it did not work, I added the update, please help – daydreamer Feb 02 '13 at 16:36
  • @daydreamer I updated my answer, if you managed to make it work before all these changes, then it should be easy to include it just in the src as I wrote in the answer.. – Lipis Feb 02 '13 at 18:12
  • @daydreamer Did that work after all?! If it did would be nice to be accepted because it keeps popping up.. – Lipis Feb 11 '14 at 09:29
  • @Lipis : I follow your guide, but i still get the error. Could you please see the capture: https://dl.dropboxusercontent.com/u/27576887/1.JPG – John Sep 14 '15 at 03:02
  • yes.. libs is a string.. not a variable.. 'libs' – Lipis Sep 14 '15 at 03:16