ImportError when using google.cloud library in app engine dev - google-app-engine

I have done the following, installed google cloud in a local lib folder with pip. Added an appengine_config.py file:
from google.appengine.ext import vendor
vendor.add("lib")
But still get:
ImportError: No module named google.cloud.bigquery
It seems there is some kind of conflict in the google namespace, since other dependendices in the lib folder seems to be possible to import.
If I just override with:
google.cloud.__path__ = ['/Users/okku/dev/MyServer/lib/google/cloud']
Then it works, but some other dependcy failes to be imported in this case google.api_core.
I have been on this for half day now. I cant find whats wrong. Any clues?

Related

GCS generate sign url with python 2.7 and google app engine

I am trying to generate signUrl in python 2.7 using v4 signing process as given here
below is the code given on the link:
def generate_singed_url(bucket_name, blob_name):
"""Generates a v4 signed URL for downloading a blob.
Note that this method requires a service account key file. You can not use
this if you are using Application Default Credentials from Google Compute
Engine or from the Google Cloud SDK.
"""
# bucket_name = 'your-bucket-name'
# blob_name = 'your-object-name'
storage_client = storage.Client()
bucket = storage_client.bucket(bucket_name)
blob = bucket.blob(blob_name)
url = blob.generate_signed_url(
version="v4",
# This URL is valid for 15 minutes
expiration=datetime.timedelta(minutes=15),
# Allow GET requests using this URL.
method="GET",
)
print("Generated GET signed URL:")
print(url)
print("You can use this URL with any user agent, for example:")
print("curl '{}'".format(url))
return url
This is how I am trying to import the storage:
from google.cloud import storage
But I am getting the error as:
File "<input>", line 1, in <module>
File "/Applications/PyCharm CE.app/Contents/plugins/python-ce/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
ImportError: No module named google.cloud
I tried installing google-cloud-storage library also tried installing lots of other google specific libraries but it's still giving the same import error.
Tried:
ImportError: No module named google.cloud
ModuleNotFoundError: No module named 'google.cloud' (uninstalling the libraries and again installing)
Edit: how can i generate signurl using python2.7 and app engine ?
I was running two python versions in my mac: python2.7 and python3 , the libraries was already installed for python3 but was missing for python2.7.
Used below command to install the library:
python2.7 -m pip install --upgrade google-cloud-storage --user
....Answering based on your comments....
If you were using Python3, you would have a virtual env and a requirements.txt file and when you deploy your project to Production, GAE would first install the contents of your requirements.txt file before running your App.
Since you're running Python2, you don't have that requirements.txt file and virtual env concept with GAE. Your App has to be uploaded together with any third party library you need (i.e. any library outside of these has to uploaded with your App). You do this via the 'lib' folder that I mentioned in the comments - (instructions for creating the folder can be found here). I believe the instructions are simple enough to follow.
I would say to first try using the lib concept on your local machine (this would mean installing the cloud storage library to that folder). It also means you have to run your app with dev_appserver.py.
Note that when you install google cloud storage client to the lib folder and run your app with dev_appserver.py, GAE will use the package in your lib folder instead of the one installed globally on your laptop.
If it works (i.e. you're able to create signed urls on your local machine), then go ahead and deploy to production.
If you have problems creating the lib folder and installing packages to it, let me know.

ImportError: No module named google.appengine.ext.webapp.mail_handlers

I'm trying to get google app engine to work on my Raspberry Pi. I keep getting this error.
Traceback (most recent call last):
File "main.py", line 26, in <module>
from google.appengine.ext.webapp.mail_handlers import InboundMailHandler
ImportError: No module named google.appengine.ext.webapp.mail_handlers
I downloaded google app engine and then ran these commands:
unzip google_appengine_1.9.40.zip
export PATH=$PATH:/home/pi/google_appengine/
The most trivial solution for such errors is to import the required package into you project directory. but to be honest it is not the best way to resolve this one. you may use Google App Engine SDK which will take care of all that headache, or there are another way you can follow:
Create a folder into your project directory and call it lib
Add all required packages into this folder.
Create a .py file and name it appengine_config.py
Add the below code snippets into this file:
import sys
import os.path
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'lib'))
appengine_config.py gets loaded every time a new instance is started, and should take care of your modules importing.
Regards.
It appears you're trying to directly execute your main.py as a standalone application, which is not how GAE app code works.
You're supposed to get the development server (from the SDK you downloaded) to execute your app code on your development machine (on GAE it's the GAE infra doing that). See Using the Local Development Server.

PyDev PDFMiner GAE: ImportError: No module named pdfminer.converter

I work on GAE project in PyDev
I'd like to use the PDFminer library in order to convert a pdf file to a text file.
My problem is when i run the application it dosn't work and it displays this error message :
ImportError: No module named pdfminer.converter
I tested the same code in a normale python project and it works fine.
I used the same code in python console and it works too
I add the pdfminer folder to the python interpreter, i removed the interpreter and i add it again but i have always the same error.
Really i don't what i have to do, can anybody help me please ?
The problem comes from the fact that the PDFMiner is a third party library i copied the PDFMiner's files into the project and i works fine GAE don't import lib if isn't a pure python even if it exits in PYTHONPATH I found the solution in this post: Google App Engine "no module named requests" PyDev

Installing QuantLib python SWIG module on Google app engine

I am new to GAE. I wish to use the QuantLib python library (SWIG) as a module inside google app engine. I was following this blog post to set up QuantLib-SWIG on Ubuntu. http://blog.quantess.net/2012/09/26/quantlib-get-it-working-on-ubuntu/
I have compiled the modules for python using make -c Python after installing the required boost c++ libraries as mentioned in the post.
I've copied the QuantLib folder to my app folder. The QunatLib folder contains the following files:
__init__.py
__init__.pyc
QuantLib.py
QuantLib.pyc
_QuantLib.so*
This is my app directory structure:
app.yaml
index.py
QuantLib/
However, when I do an
import QunatLib
in the index.py in my app folder, I get the following error:
<type 'exceptions.ImportError'>: No module named _QuantLib
args = ('No module named _QuantLib',)
message = 'No module named _QuantLib'
I also get this is dev_appserver logs:
ImportError: No module named _QuantLib
_QuantLib is a .so file. Is there a way I can fix this problem? Or any other way to use QuantLib libraries for GAE?
Thanks.
No.
There are a limited number of 3rd party libraries that are not pure python. You cannot add your own non pure python libraries to appengine runtime.
Here is the current list of included 3rd party libs https://developers.google.com/appengine/docs/python/tools/libraries27
You can add any pure python libraries in your own code base.

ImportError: cannot import name taskqueue

I am trying to use AppEngine TaskQueue API, so I import it like this:
from google.appengine.api import taskqueue
The code works perfectly online. But when I try to run it locally, I get this error:
ImportError: cannot import name taskqueue
I checked the directory of AppEngine and I didn't find the file taskqueue.py which explains the error. Is there any reason why this file isn't included in the AppEngine SDK? And is there anyway to install it locally? I wouldn't trust just copying the file to the folder, because I am sure it depends on tens of other files.
Download and install the current SDK. You're using an older version.
OK, I found the solution for this myself. I just downloaded the latest AppEngine SDK (version 1.4) and it has the taskqueue.

Resources