问题
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