对于我的gae python项目,我想导入一个名为'vobject'的外部库。在我的.py文件中导入它的正确方法是什么?在GAE项目中引入和引用第三方库
该项目的自述说,为了安装它,你需要运行
python setup.py install
此外,VOBJECT要求“dateutil”包。
因为这将在GAE上运行,所以我认为我应该将这两个库都复制到我的项目中,而不是运行安装脚本以便在我的代码中使用它。
但我收到一堆导入错误,我不确定外部gae/python库的正确约定是什么。
utc = dateutil.tz.tzutc()
## error produced:
File "myGaeProject/external/vobject/icalendar.py", line 47, in <module>
NameError: name 'dateutil' is not defined
的因为我构建我的项目的方式,我改变了icalendar.py的进口结构从:
import dateutil.rrule
import dateutil.tz
到:
import external.dateutil.rrule
import external.dateutil.tz
我也试过:
from external.dateutil import *
什么是正确的进口机anism结构性像这样一个项目:
-myGaeProject
--external
----__init__.py
----dateutil
------__init__.py
------tz.py
------rrule.py
------[more dateutil files]
----vobject
------__init__.py
------base.py
------icalendar.py
--handlers
------__init__.py
------mainHandler.py
你会在只有一个py文件或包含外部库的所有文件中执行此操作吗? –
@Dan通常你会把它放在一个你想导入外部库的地方(或者你知道会在这些库之前运行的地方,比如你的脚本处理程序中)导入的模块中。 –