本文介绍了Python 2.7:如何在Google App Engine中使用BeautifulSoup?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
限时删除!!
我试图追踪:
from bs4 import BeautifulSoup
并得到错误
Traceback(最近一次调用最后):
文件/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/admin/__init__.py,行后355
exec(compiled_code,globals())
在< module>中,第1行的文件< string>
ImportError:没有名为bs4的模块
如何将它与 Google App Engine运行时2.7 ?
更新
我的项目结构看起来像
flask-appengine-template /
文档/
许可证/
src /
应用程序/
static /
模板/
models.py
settings.py
urls.py
views.py
libs /
bs4 /
app.yaml
src.py
我是使用
由于 app.yaml
的父项为 src
,我添加了一个文件 src.py
,并在那里添加了两行。
我仍然看到相同的错误
ImportError:没有名为bs4的模块
然而,根据 app.yaml
的项目名称是 flaskonappengine
请告诉我我还在做什么错误? 解决方案
如果您想使用未包含的第三方库这个列表,那么你必须手动添加它们。
为了手动包含任何其他库,您必须将它们放在 app.yaml
所在的目录中。例如,如果你有以下结构:
hello
├──libs
│└─ ─bs4
├──hello.py
└──app.yaml
然后在你的 hello.py
中,你必须把这两行放在文件的开头:
import sys
sys.path.insert(0,'libs')
完成这些之后,您将可以使用任何您要放入 libs
目录的第三方库。例如:
from bs4 import BeautifulSoup
Update
由于您使用的是框架,所以需要回滚您的更改并使用与烧瓶或werkzeug相同的模式或其他第三方库。只需将bs4放入src目录并尝试正常包含它即可。
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 hereSince 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
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.
这篇关于Python 2.7:如何在Google App Engine中使用BeautifulSoup?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
1403页,肝出来的..