Need help understanding module import errors

北城以北 提交于 2019-12-10 20:33:59

问题


I'm trying to use the sendgrid Python API as a module in web2py. After testing it successfully from the command line, I dropped it into my modules folder, but as soon as I try to import sendgrid into my controller file, I get:

File "applications/test/modules/sendgrid/__init__.py", line 4, in
<module>
    del sendgrid, message NameError: name 'sendgrid' is not defined

Looking at the __init__.py file, I noticed they're doing * imports on the module level, which I've seen cause problems before, but I'm not sure what the issue is.

sendgrid/__init__.py:

from sendgrid import *
from message import *

del sendgrid, message

__version__ = "0.1.0"
version_info = (0, 1, 0)

sendgrid api: https://github.com/sendgrid/sendgrid-python


回答1:


Generally, the best practice for 3rd party modules is to install them via pip or easy_install (preferably in a virtualenv), if they're available on PyPI, rather than copying them somewhere onto your PYTHONPATH.

Try removing the sendgrid package from your modules folder and doing pip install sendgrid-python or easy_install sendgrid-python if pip isn't available.



来源:https://stackoverflow.com/questions/10760945/need-help-understanding-module-import-errors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!