且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

python谷歌应用程序引擎条带集成

更新时间:2022-10-21 15:25:03

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


最简单的管理方法是使用./lib目录:


  1. 使用pip安装库和供应商模块以启用从第三方库目录导入包。


  2. 在您的应用程序根目录中创建一个名为lib的目录:

      mkdir lib 
    $ c $为了告诉你的应用程序如何在这个目录中找到库,创建或修改一个名为appengine_config.py的文件在你的$的根目录下b $ b项目,然后添加这些行:

      from google.appengine.ext导入供应商

    #添加任何安装在lib文件夹中的库。
    vendor.add('lib')


  3. lib标志将库安装在这个目录下:

      pip install -t lib gcloud 

笔记

>


  • 阅读提及的文档页面时请注意,因为它还包含请求和使用GAE提供的内置库 - 与已安装/已售货库不同。

  • 如果您的应用是多模块库对于使用位于模块 .yaml 旁边的步骤#3的库的每个模块,都需要一个 appengine_config.py >文件。如果您愿意,可以将其配置为DRY原因(请参阅 https://***.com/a/34291789/4495081 ) 。步骤#4的目标是将条带库的内容放入 lib $ c $的子目录中c> dir。如果因任何原因导致pip方式失败,您可以手动执行此操作。

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:

  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://***.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.