Yarin
Yarin

Reputation: 183499

Need help understanding module import errors

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

Upvotes: 3

Views: 1040

Answers (1)

shakefu
shakefu

Reputation: 91

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.

Upvotes: 4

Related Questions