AppEngine服务器无法导入原子模块 [英] AppEngine server cannot import atom module

查看:95
本文介绍了AppEngine服务器无法导入原子模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的ArchLinux上安装了gdata库,还有一个简单的应用程序,它在开始时导入原子库,当我运行gapp引擎并访问该web应用程序时,


$ python2.5 ./dev_appserver.py〜/ myapp


抛出异常'No module named atom 。但是当我在Python2.5交互模式下运行'import atom'时,它运行良好。如何在我的GAppEngine应用程序中导入原子模块?

解决方案

将atom.py添加到您保留的相同目录GAE Python源代码并确保在您上传应用时将其上传到服务器。 (上传发生在你执行 appcfg.py更新myapp / 时,除非你想方设法停止它;使用 - verbose
$ b

(或者,如果它是一个大文件,请在其中创建一个zip文件并在其中创建一个zip文件您的处理程序会将该zip文件附加到sys.path中;例如,请参阅 zipimport )。



这假定您有一个文件 atom.py ,这是您导入的文件;如果该文件轮流导入其他文件,则必须以类似的方式使其他文件可用,等等(请参阅

如果<$ c <-c <-c> $ c> atom 不是一个模块,而是一个包,那么你得到的 import __ init __。py 文件在该包的目录中;所以同样的建议也适用(并且zipimport变得更具吸引力,因为您可以轻松地打包任何目录结构,例如在Linux命令行中使用 zip -r 命令)。



如果在任何时候(如modulefinder将帮助您发现),则会依赖于第三方C编码扩展名( .so .pyd Python可以使用但不是用纯Python编写的文件),它不在GAE提供的短列表中(请参阅 here ),那么Python代码在GAE上不可用,因为GAE仅支持纯Python。如果是这种情况,那么您必须寻找GAE支持的替代方案,即纯Python方法来获得您需要的相同功能。


I have gdata library install on my ArchLinux, and a simple application which imports atom library at the beginning, when I run gapp engine and access that web app,

$ python2.5 ./dev_appserver.py ~/myapp

It throws exception 'No module named atom'. But when I run 'import atom' in Python2.5 interactive mode, it works well. How can I import atom module in my GAppEngine applications?

解决方案

Add atom.py to the same directory you keep you GAE Python sources in, and make sure it's uploaded to the server when you upload your app. (The upload happens when you do appcfg.py update myapp/ unless you go out of your way to stop it; use the --verbose flag on the command to see exactly what's being uploaded or updated).

(Or, if it's a large file, make a zipfile with it and in your handler append that zipfile to sys.path; see zipimport for example).

This assumes that you have a single file atom.py which is what you're importing; if that file in turns imports others you'll have to make those others available too in similar ways, and so on (see modulefinder in Python's standard library for ways to find all modules you need).

If atom is not a module but a package, then what you get on import is the __init__.py file in the directory that's the package; so the same advice applies (and zipimport becomes much more attractive since you can easily package up any directory structure e.g. with a zip -r command from the Linux command line).

If at any point (as modulefinder will help you discover) there is a dependency on a third party C-coded extension (a .so or .pyd file that Python can use but is not written in pure Python) that is not in the short list supplied with GAE (see here), then that Python code is not usable on GAE, as GAE supports only pure-Python. If this is the case then you must look for alternatives that are supported on GAE, i.e. pure-Python ways to obtain the same functionality you require.

这篇关于AppEngine服务器无法导入原子模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆