I installed the App engine SDK, then did a pip install requests and pip install requests-toolbelt (under VENV). when running the app in the local development server - I get the following error:
ERROR 2017-05-31 18:14:52,315 cgi.py:122] Traceback (most recent call last):
File "/Users/assafshamia/Freebird/Techradar/dev/scraper.py", line 8, in <module>
import requests
ImportError: No module named requests
I followed the steps of installing a 3rd party library (appengine_config.py and install requests under /lib)
what is going on???
I was able to resolve this by adding the following code to my Python app (main.py) in order to access the libraries at /lib:
import sys
sys.path.insert(0, 'lib')
Per the docs, you need to add the requests library code to your application directory. pip install is not enough.
You can include third party Python libraries with your application by
putting the code in your application directory.
Edit:
Additionally:
The include path of the Python module includes your application's root directory, which is the directory containing the app.yaml file. Python modules that you create in your application's root directory are available using a path from the root. Don't forget to create the required init.py files in your sub-directories so that Python recognizes those sub-directories as packages.
Related
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.
I'm testing Google App Engine and trying to run a simple function to upload files to either the Blobstore or Cloud Storage. I'm typing the Python code directly in the Cloud Shell of my instance. The code is failing when I call:
from google.appengine.ext import blobstore
I get the error code:
Traceback (most recent call last):
File "upload_test.py", line 1, in <module>
from google.appengine.api import users
ImportError: No module named 'google.appengine'
Even though the documentation says that: You can use Google Cloud Shell, which comes with git and Cloud SDK already installed, I've tried installing a bunch of libraries:
gcloud components install app-engine-python
pip install google-cloud-datastore
pip install google-cloud-storage
pip install --upgrade google-api-python-client
I'm still getting the same error. How can I get the appengine library to work? Alternatively, is this the wrong method for creating an app that allows the user to upload files?
The google.appengine module is baked into the first-generation Python (2.7) runtime. It's not available to install via pip, in the second-generation (3.7) runtime, or in Cloud Shell.
The only way to use it is by writing and deploying a first-generation App Engine app.
Thanks #Dustin Ingram
I found the answer in this page.
The current "correct" way of uploading to Cloud Storage is to use google.cloud.storage. The tutorial I linked above explains how to implement it.
The impression I have, however, is that this uses twice the bandwidth as the solution via google.appengine. Originally, the front-end would receive an upload url and send the file directly to the Blobstore (or to Cloud Storage). Now the application uploads to the back-end which, in turn, uploads to Cloud Storage.
I'm not too worried, as I will not be dealing with excessively large files, but it seems strange that the ability to upload directly has been discontinued.
In any case, my problem has been solved.
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.
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.
I downloaded and installed requests library for Python 2.7. Using the shell I can make "import requests" and actually use it without problems.
Thing is that when running Google App Engine it can't find it and prompts the error:
ImportError: No module named requests
I'm using PyDev-Eclipse as IDE for my project and tried adding the path (/usr/local/lib/python2.7/dist-packages/requests) both in
Project > properties > PyDev - PYTHONPATH > External Libraries
and in
Window > preferences > Pydev -Interpreter > Libraries
and none worked! Still having the same issue when trying to run my GAE app
Anyone could help?
Thanks!
Any 3rd party lib you use must be physically included in your project and deployed to appengine. This means it is not sufficient to just install with easy_install or pip
See the docs https://developers.google.com/appengine/docs/python/runtime#Pure_Python