Migrating a legacy project from 2.7 and Ubuntu 18.04 [piecemeal, Python 3.10 & 22.04 next… then Flask!] from vendored dependencies to requirements.txt
. Removed dependencies from project root and enumerated them in my requirements.txt
.
My requirements.txt
contains google-cloud-storage==1.44.0
and was venv-2-7/bin/python -m pip install -t lib -r requirements.txt
with a appengine_config.py
in same dir as app.yaml
with:
# From https://cloud.google.com/appengine/docs/legacy/standard/python/tools/using-libraries-python-27
import os
from google.appengine.ext import vendor
vendor.add('lib')
vendor.add(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'lib'))
How do I resolve this error? - Attempted venv-2-7/bin/python -c 'import google.cloud.storage'
which worked, but:
$ venv-2-7/bin/python /google-cloud-sdk/platform/google_appengine/dev_appserver.py --host 127.0.0.1 .
Errors [from PyCharm & manually] with:
ImportError: No module named google.cloud.storage
EDIT0: Including more information [below] as per comment requests:
app.yaml
runtime: python27
api_version: 1
threadsafe: yes
instance_class: F4
automatic_scaling:
min_idle_instances: automatic
handlers:
- url: /1/account.*
script: api_account.app
inbound_services:
- warmup
libraries: # Also tried removing this section entirely
- name: webapp2
version: latest
- name: jinja2
version: latest
- name: ssl
version: latest
env_variables:
PYTHONHTTPSVERIFY: 1
skip_files:
- ^(.*/)?.*\.py[co]$
EDIT1: Tried both solutions independently and even together:
import os
import sys
import pkg_resources
import google
if os.environ.get("GOOGLE_CLOUD_SDK_APPENGINE"):
sys.path.insert(0, os.environ["GOOGLE_CLOUD_SDK_APPENGINE"])
for lib_dir in os.path.join(os.path.dirname(__file__), 'lib'), 'lib':
sys.path.insert(0, lib_dir)
google.__path__.append(os.path.join(lib_dir, 'google'))
pkg_resources.working_set.add_entry(lib_dir)
import google.cloud.storage
Is there some trick with from google.appengine.ext import vendor
, should I not be using /google-cloud-sdk/platform/google_appengine
as my GOOGLE_CLOUD_SDK_APPENGINE
env var?
EDIT2: I tried inlining google.appengine.ext.vendor
and calling it in the loop, which gave me a ImportError: No module named google.cloud._helpers
error