python google 应用引擎条带集成

python google app engine stripe integration

我正在做一个项目,我想在其中集成 stripe 进行支付。我正在按照他们的文档将其集成到 python Stripe Documentation 中。在文档中,他们下载了 stripe 库来使用它。下载它的代码是:

pip install --upgrade stripe

我遵循了相同的步骤。但是我收到了这个错误。当我尝试将它导入我的项目时。

import stripe
ImportError: No module named stripe

当您 pip 安装 stripe 时,它​​会将其安装在您的本地系统中。但是 GAE 没有那个包,所以你不能简单地在生产中导入它。您需要下载包,并将其添加到您的应用程序中。例如,在 "libs" 目录中。然后,它会在您部署时与您的应用程序的其余部分一起上传,并可供应用程序使用。然后,你像这样导入它:

from libs import stripe

假设您的应用结构如下所示:

- myapp
  - app.yaml
  - otherstuff.py
  - libs
    - stripe

Installing a library:

中描述了将第 3 方库安装到 GAE 应用程序中的正确方法

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
    

备注

  • 浏览上述文档页面时请注意,因为它还包含有关请求和使用 GAE 提供的 内置 库的说明 - 不同于installed/vendored-in 库。

  • 如果您的应用是多模块应用,您需要为使用第 3 步中的库的每个模块创建一个 appengine_config.py,位于模块的 .yaml 文件旁边.如果您愿意,可以出于 DRY 的原因对其进行符号链接(参见 )。

  • 第 4 步的目标是将条带库的内容放入 lib 目录的子目录中。如果 pip 方式因任何原因失败,您可以手动执行此操作。