1

Hi I installed on a Google App Engine Python 2.7, opencv using

pip install -t lib -r requirements.txt

requirements.txt is:

Flask==0.12.1
Werkzeug==0.12.2
Opencv_python==3.3.0.10

Install worked, I can use other libraries, but when I try to import opencv on code, it throws the next exception:

  File "/google/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 85, in LoadObject
    obj = __import__(path[0])
  File "/home/tcarrillof/python-docs-hello-world/main.py", line 23, in <module>
    import cv2
  File "/home/tcarrillof/python-docs-hello-world/lib/cv2/__init__.py", line 6, in <module>
    os.environ["PATH"] += os.pathsep + os.path.dirname(os.path.realpath(__file__))
  File "/google/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/request_environment.py", line 126, in __getitem__
    return self._request.environ[key]
KeyError: 'PATH'

Is it there something I need to configure?, Any help is welcome in advance :)

Note:

app.yaml is:

runtime: python27
api_version: 1
threadsafe: true

handlers:
- url: /static
  static_dir: static
- url: /.*
  script: main.app

and appengine_config.py is:

import os
from google.appengine.ext import vendor

vendor.add(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'lib'))
BrettJ
  • 6,801
  • 1
  • 23
  • 26
Pregunton
  • 77
  • 7

2 Answers2

4

This is less something you need to configure, and more something to abandon. OpenCV won't run in the standard App Engine environment. OpenCV is a big chunk of C++ (with Python wrappers). App Engine only supports libraries that are pure Python unless they're on the list in https://cloud.google.com/appengine/docs/standard/python/tools/using-libraries-python-27

If you need OpenCV, consider using the Flex environment.

Dave W. Smith
  • 24,318
  • 4
  • 40
  • 46
  • Another option could be to use [Google Cloud Vision API](https://cloud.google.com/vision/) if it provides the needed functionality. – new name Nov 16 '17 at 12:14
0

You could try using Cloud Function which might make life simpler

You can see in Support Python in Cloud Functions the last comment you can find a link to this cloud-functions-python

You can just list opencv as one libraries required along with other libraries such as numpy and matplotlib generally used along with any others you might actually want to use.

How to install OpenCV using pip here's a nice answer I found on stackoverflow answers

Santhosh
  • 1,554
  • 1
  • 13
  • 19