1

I have the following folders structure:

myappdir
  - libs
    - somelib
      script1.py
      script2.py
    - google
      - protobuf
          __init__.py
          message.py
          ...
      __init__.py
      ...
    app.yaml
    appengine_config.py
    ...

And the following files content -

appengine_config.py:

import sys
sys.path.append('libs')

script1.py:

from somelib.script2 import Something

script2.py:

from google.protobuf import message

In result I get:

  File "myappdir/libs/somelib/script1.py", line 34, in <module>
    from somelib.script2 import Something
  File "myappdir/libs/somelib/script2.py", line 38, in <module>
    from google.protobuf import message
ImportError: No module named protobuf

What is wrong with my setup?

LA_
  • 19,823
  • 58
  • 172
  • 308

2 Answers2

0

Change the lines in your appengine_config.py file, from:

import sys
sys.path.append('libs')

to:

import sys
import os.path
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'libs'))
Daniel
  • 2,345
  • 4
  • 19
  • 36
0

I found @Daniel's answer to already be implemented in my setup, but still had the problem. This github comment helped me. Adding the following to appengine_config.py solved the problem for me:

from google.appengine.ext import vendor
vendor.add('lib')
import google.protobuf; print(google.protobuf.__version__)

change lib to libs depending on your project directory naming.

hamx0r
  • 4,081
  • 1
  • 33
  • 46