MichaelLis
MichaelLis

Reputation: 91

“ImportError: No module named sendgrid” for SendGrid in Google App Engine

I followed the instruction from the https://cloud.google.com/appengine/docs/python/mail/sendgrid?hl=en and added SendGrid email support to my project.

It works perfectly on the development server but when I deploy to GAE I get “ImportError: No module named sendgrid”

I know the files are on the server (I downloaded source back from GAE to test it) and I have other third party libraries that work but not the sendgrid.

I spoke to SendGrid tech support but they point back to Google.

Here is the import line from main.py

from sendgrid import SendGridClient, Mail

The project directory structure looks like this:

-+
 |
 +sendgrid
 +smtpapi
 main.py

UPDATE:

After deleting everything and adding it back bit by bit I've finally discovered what was wrong.

I had a folder for static content called "s". I didn't mentioned it because I thought it was irrelevant. After deleting this folder - sendgrid suddenly started to work. Eventually, I've changed "s" to a longer name that does not starts with "s" and problem has disappeared.

Upvotes: 3

Views: 13694

Answers (4)

Vincent Casey
Vincent Casey

Reputation: 710

For my specific scenario I was using uvicorn to run a FastAPI application. I got he error from my original command uvicorn main:app --reload. This was happening because uvicorn was running (by default) on Python version 3.9 whereas my default pip install was for Python version 3.11.

You can check your Uvicorn version with the command uvicorn --version (I got Running uvicorn 0.20.0 with CPython 3.9.13 on Windows as a result specifically).

To fix this issue simply specify the Python version you're using. I did this with the command:

py -3 -m uvicorn main:app --reload

Though I suspect that running python uvicorn main:app --reload or python3 uvicorn main:app --reload could also work depending on your environment.

Upvotes: 0

Sanjay Maharjan
Sanjay Maharjan

Reputation: 19

pip install sendgrid

Collecting sendgrid Cache entry deserialization failed, entry ignored Downloading https://files.pythonhosted.org/packages/b4/c6/d1ff0214c758d49bbc4b3761dae6d5653c3aea801ba49a9c94cc1fbf7980/sendgrid-6.4.7-py3-none-any.whl (73kB) 100% |████████████████████████████████| 81kB 952kB/s Collecting starkbank-ecdsa>=1.0.0 (from sendgrid) Cache entry deserialization failed, entry ignored Downloading https://files.pythonhosted.org/packages/4c/48/29de0f3876d8f89906372da49f132e5c5e46e2fa601a198a9eca6402f646/starkbank-ecdsa-1.1.0.tar.gz Collecting python-http-client>=3.2.1 (from sendgrid) Cache entry deserialization failed, entry ignored Downloading https://files.pythonhosted.org/packages/d9/93/fffa7a16e735ae8b946a58e2521e71180803440edc2a0de0d2e9d4a93b84/python_http_client-3.3.1.tar.gz Installing collected packages: starkbank-ecdsa, python-http-client, sendgrid Running setup.py install for starkbank-ecdsa ... done Running setup.py install for python-http-client ... done Successfully installed python-http-client-3.3.1 sendgrid-6.4.7 starkbank-ecdsa-1.1.0 You are using pip version 9.0.1, however version 20.2.4 is available. You should consider upgrading via the 'python -m pip install --upgrade pip' command.

Upvotes: -1

MichaelLis
MichaelLis

Reputation: 91

I had a folder for static content called "s" which I didn't mention in the question because I thought it was irrelevant. After I renamed this folder everything started to work. So the issue has been resolved, however the cause of it still remains a mystery ...

Upvotes: 1

Vamsidhar Muggulla
Vamsidhar Muggulla

Reputation: 632

install the sendgrid module in ur virtual environment using the following command

pip install sendgrid

or else u can install it as system wide module by typing

sudo apt-get install sendgrid

see how I solved it. enter image description here

Upvotes: 4

Related Questions