0

I have a Flask application deployed on an Amazon Elastic Beanstalk cluster. On my local machine, macOS, I've added an integration with the Google Cloud API, and I've updated my requirements.txt to include the line google-cloud==0.27.0. When I deploy to Elastic Beanstalk with the updated requirements file, my deployment fails during pip install with the error

Running setup.py install for grpcio
      Complete output from command /opt/python/run/venv/bin/python3.4 -c "import setuptools, tokenize;__file__='/tmp/pip-build-ve1vz0tx/grpcio/setup
.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-aszzosux-rec
ord/install-record.txt --single-version-externally-managed --compile --install-headers /opt/python/run/venv/include/site/python3.4/grpcio:
      Failed to import the site module
      Traceback (most recent call last):
        File "/opt/python/run/venv/lib64/python3.4/site.py", line 890, in <module>
          main()
        File "/opt/python/run/venv/lib64/python3.4/site.py", line 848, in main
          virtualenv_search_paths(sys.prefix)
        File "/opt/python/run/venv/lib64/python3.4/site.py", line 638, in virtualenv_search_paths
          addsitedir(sitedir, known_paths)
        File "/opt/python/run/venv/lib64/python3.4/site.py", line 204, in addsitedir
          addpackage(sitedir, name, known_paths)
        File "/opt/python/run/venv/lib64/python3.4/site.py", line 173, in addpackage
          exec(line)
        File "<string>", line 1, in <module>
      KeyError: 'google'

I am able to install my requirements locally in a virtualenv running python 3, however, when I create a similar virtualenv on my ec2 and install the requirements, I get the same error I get during deployment. One thing I have read about is that the ec2 might not have google cloud sdk installed, however, I installed it on my ec2 (tested both inside and outside of a virtualenv) using the following commands as described here here:

curl https://sdk.cloud.google.com | bash
exec -l $SHELL
gcloud init

How can I diagnose this error and prevent it from happening going forward?

My current hypotheses are:

  1. there is still an issue with the way google cloud sdk is install or operating on the ec2
  2. there is some conflict between requirements in my requirements.txt file once I add the google-cloud requirement

1 Answers1

0

I've identified and fixed the problem. I had google==1.9.2 as a package in my requirements.txt and it wasn't playing well with google-cloud==0.27.0. I'm not sure why this occurred though.

Note: when deploying to Elastic Beanstalk, I had to rebuild the environments for the change to take place. It seems like Elastic Beanstalk reuses the Python virtualenv across deploys, so if a server had ever run a version of my application with google==1.9.2 in requirements, that previously installed version of google would interfere with future deploys that excluded it