python google app engine stripe integration - python

I am working on a project in which i want to integrate stripe for payments. I am following their documentation to integrate it in python Stripe Documentation. In documentation they downloaded the stripe library to use it. The code to download it was:
pip install --upgrade stripe
I followed the same steps. But i am getting this error. When i try to import it in my project.
import stripe
ImportError: No module named stripe

The proper way to install a 3rd party library into your GAE application is described in Installing a library:
The easiest way to manage this is with a ./lib directory:
Use pip to install the library and the vendor module to enable importing packages from the third-party library directory.
Create a directory named lib in your application root directory:
mkdir lib
To tell your app how to find libraries in this directory, create or modify a file named appengine_config.py in the root of your
project, then add these lines:
from google.appengine.ext import vendor
# Add any libraries installed in the "lib" folder.
vendor.add('lib')
Use pip with the -t lib flag to install libraries in this directory:
pip install -t lib gcloud
Notes:
When going through the mentioned doc page pay attention as it also contains instructions for requesting and using GAE-provided built-in libraries - different than those for installed/vendored-in libraries.
if your app is a multi-module one you'll need an appengine_config.py for each module using the library at step#3, located beside the module's .yaml file. It can be symlinked for DRY reasons if you prefer (see https://stackoverflow.com/a/34291789/4495081).
step #4's goal is to just bring the content of the stripe library in a subdirectory of the lib dir. You can do that manually if the pip way fails for whatever reason.

When you pip installed stripe, it installed it in your local system. But GAE does not have that package, so you cannot simply import it in production. You need to download the package, and add it inside your app. For example, in a "libs" directory. Then, it will upload with the rest of your app when you deploy, and be available to the app. Then, you import it like this:
from libs import stripe
Assuming your app structure looks like this:
- myapp
- app.yaml
- otherstuff.py
- libs
- stripe

Related

Google App Engine ImportError: No module named

I am creating a Python Web App in Google App engine.
When I
sudo pip install
a third party library and then try to import it, I get the error 'ImportError: No module named x'. Where x is the name of that library. In my case as an example: Boto, Boto3, Fask etc.
If I go into shell in GAE and type python >> import X the library can be used inside the python environment. When deploying the app though or running the app in the virtaul server in Google App Engine I get the module import error.
I even tried methods like: python >> import sys >> sys.path.insert(0, "path_here")
export PYTHONPATH and selected where those libraries are located
I even followed several Q&A here in Stackoverflow without any success, can somebody please give me a proper way to fix the import error in Google App Engine?
FYI
I am not using any local environment in my pc, I am working directly through the GAE bash console, the launch code editor in GAE and I am running the command dev_appserver.py $PWD
When I do
pip freeze
I can see that the modules are currently installed and deployed on the GAE virtual environment. Is there a problem with my path? What's the best approach to make GAE load my already installed third party libraries.
UPDATE:
Importing the library directly on the python shell from Google App Engine works just fine. Importing the library on my python app index.py file results in the error.
Python import directly from Shell
Python import to the index.py file
Though this is an old thread, adding this answer now:
Run command : gcloud components list
This will show the different components installed and not in your environment.
Install app-engine-python components if not installed:
gcloud components install app-engine-python
gcloud components install app-engine-python-extras
If it doesn't work:
In Windows, uninstall and download and install Google-sdk (check the python version you need). Delete all the files the installer ask you to delete in the last step and run the gcloud component commands again.

How to prevent "ImportError: No module named oauth2client.client" on Google App Engine?

We are receiving an error:
ImportError: No module named OAuth2Client
We have noticed scores of questions around this topic, many unanswered and at least one answer that describes the solution of copying over files from the Google App Engine SDK.
This approach, however, seems tedious because all the dependencies are unclear. If we copy over oauth2client then run, the next error is another module that is missing. Fix that, then another module is missing, etc., etc.
What is ironic is that we can see all the files and modules needed, listed from Google App Engine SDK right in PyCharm but they seem inaccessible to the script.
Is there no better way to pull in all the files that oauth2client needs for Python to work on App Engine?
I have this problem and solved by installing oauth2client with pip3:
pip3 install --upgrade oauth2client
As per the google-api-python documentation, try this
pip install --upgrade google-api-python-client oauth2client
The answer is to "vendor" in the file(s).
We found a quick way to solve this based on this documentation https://cloud.google.com/appengine/docs/python/tools/libraries27#vendoring
and this SO answer.
Create a new folder called "lib" in the same folder as your app.yaml file. (You can name it something else. Just use that name below.)
Create an empty file called appengine_config.py in the same folder as your app.yaml file
Add two lines to that appengine_config.py file:
from google.appengine.ext import vendor
vendor.add('lib')
From terminal, navigate to the directory which contains that file and execute the following command:
sudo pip install -t lib google-api-python-client
The import error will disappear and you will have all the sub-dependent modules as well.
Install WHL file
pip install oauth2client-4.1.3-py2.py3-none-any.whl
Run this
sudo python -m pip install oauth2client

can't import google.appengine.api

This should be pretty basic as I've installed lots of python packages, but I can't for the life of my get google apis client library for python to install.
I'm pressure sure I've gone through the instructions on this website properly:
https://developers.google.com/api-client-library/python/start/installation
To summarize I've done the following:
$ easy_install --upgrade google-api-python-client
this seems to work fine, doesn't report any errors or warnings
downloaded and unzipped google-api-python-client-gae-1.2.zip into the directory where my project is
but if I open an iPython session in the folder where I unpacked the full dependencies I can't do the basic imports such as:
import google.appengine.api it just says "No Module named google.appengine.api"
I checked in my site-packages folder and google_api_python_client-1.2-py2.7.egg is there. But it doesn't show up in sys.path
when I do sys.path.append('C:\Anaconda\Lib\site-packages\google_api_python_cli
ent-1.2-py2.7.egg') it adds the correct path, but the import still doesn't work.
EDIT: This fixed my problem
Adding the Google SDK to my Python path did the trick. I don't know why the installer didn't do this when I ran it. but hey, this worked
So if I run:
sys.path.append('C:\\Program Files (x86)\\Google\\google_appengine')
from google.appengine import api
works!
Without knowing all the steps you took to install app engine and the client APIs, my only recommendation is to install (or reinstall) the Google App Engine Python SDK from here: https://developers.google.com/appengine/downloads#Google_App_Engine_SDK_for_Python. Looks like you're on windows, so you would grab the MSI.
Just make sure you launch the AppEngineLauncher application after installation as it will give you the option to create symlinks so you can run commands from terminal.

Google App Engine Cloud Storage Client won't Install

I am trying to learn how to use Google Cloud Storage with Python.
My app is location is: myapp/lib
The documentation says to use:
"pip install GoogleAppEngineCloudStorageClient -t myapp/lib"
When I do I get:
"error: must supply either home or prefix/exec-prefix -- not both"
I have never used pip to install to a specific directory, I have just used it for my local Python installation.
I am under the impression that you need to be able to install 3rd party modules in the libs directory of your app in order for Google App Engine to use them. Is this correct?
How do people do this?
Leon
I had a similar issue when trying to install BeautifulSoup. Finally I had just downloaded it manually and put it in a folder named 'bs4' inside of 'libs' and using it like this:
sys.path.insert(0, 'libs')
from bs4 import BeautifulSoup
You should be able to download GCS from SVN as well, check out these links:
https://developers.google.com/appengine/docs/python/googlecloudstorageclient/download
https://developers.google.com/appengine/docs/python/googlecloudstorageclient/#Python_What_to_do_next
My app worked perfectly with BeautifulSoup in the 'libs' folder when deployed to google cloud appengine.
You can cd to the app directory and just run "pip install GoogleAppEngineCloudStorageClient -t lib".
Alternatively, it can be downloaded directly from here. You can then move the cloudstorage folder with your app.
To install the client library on Windows 7 in my project, I used:
C:\Python27\scripts>pip install setuptools --no-use-wheel --upgrade
C:\Python27\scripts>pip install GoogleAppEngineCloudStorageClient -t <my_app_directory_root>
More here.

Using Httplib2 on Python Appengine

Why am I getting this error when running my application which is trying to OAuth with Foursquare?
import httplib2
ImportError: No module named httplib2
I have installed httplib2 by downloading it and $ python setup.py install on the command line as instructed here
Am I missing something? Thanks
You will need to include the library in your project so that the App Engine runtime knows what you're importing.
From here:
You can include other pure Python libraries with your application by putting the code in your application directory. If you make a symbolic link to a module's directory in your application directory, appcfg.py will follow the link and include the module in your app.
I've created a simple example on how to do this when using Google App Engine. (https://github.com/muanis/foursquare-oauth-bootstrap) basically you need Google oAuth2 Client (http://code.google.com/p/google-api-python-client/) and httplib2 (http://code.google.com/p/httplib2/)
Add httplib2 as a third party library as documented here:
https://cloud.google.com/appengine/docs/python/tools/libraries27#vendoring
Install with:
pip install -t lib httplib2
https://developers.google.com/api-client-library/python/start/installation
To install the library and all of its dependencies in an App Engine
project, download the file named google-api-python-client-gae-N.M.zip
from the list of downloads, where N.M is the version number of the
latest release. Unzip that file into your project.

Categories