python google app engine stripe integration

2019-07-22 09:34发布

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

2条回答
女痞
2楼-- · 2019-07-22 10:01

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
查看更多
We Are One
3楼-- · 2019-07-22 10:04

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:

  1. Use pip to install the library and the vendor module to enable importing packages from the third-party library directory.

  2. Create a directory named lib in your application root directory:

    mkdir lib
    
  3. 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')
    
  4. 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.

查看更多
登录 后发表回答