使用外部库在谷歌云应用程序引擎上部署Django项目

时间:2021-05-14 15:42:32

Good day!

美好的一天!

I need to deploy an app on Python Django with following libs:

我需要在Python Django上部署一个具有以下libs的应用程序:

  • certifi==2017.4.17
  • certifi = = 2017.4.17
  • chardet==3.0.4
  • chardet = = 3.0.4
  • Django==1.11.2
  • Django = = 1.11.2
  • httplib2==0.10.3
  • httplib2 = = 0.10.3
  • idna==2.5
  • idna = = 2.5
  • oauth2==1.9.0.post1
  • oauth2 = = 1.9.0.post1
  • psycopg2==2.7.1
  • psycopg2 = = 2.7.1
  • pytz==2017.2
  • pytz = = 2017.2
  • requests==2.18.1
  • 请求= = 2.18.1
  • urllib3==1.21.1
  • urllib3 = = 1.21.1

And I have to connect it to PostgreSQL database.

我必须把它连接到PostgreSQL数据库。

So, what environment shall I use? Standard or Flexible?

那么,我应该使用什么环境呢?标准或灵活吗?

And how shall I install those libraries to the environment?

如何将这些库安装到环境中?

P.S.

注:

I've tried everything: app.yaml, appengine_config.py, I has installed libs directly to source ('libs' folder), and adding libs to app.yaml, and even google.appengine.ext.ndb.django_middleware.NdbDjangoMiddleware

我尝试了所有的东西:app.yaml, appengine_config。py,我已经将libs直接安装到source ('libs'文件夹),并将libs添加到app.yaml,甚至google. appengine.ext.ext .ndb. django_middlewar.ndbdjangomileware

In the end I have:

最后我有:

ImproperlyConfigured: Error loading psycopg2 module: dynamic module does not define init function (init_psycopg)

加载psycopg2模块:dynamic模块没有定义init函数(init_psycopg)

1 个解决方案

#1


1  

So, what environment shall I use? Standard or Flexible?

那么,我应该使用什么环境呢?标准或灵活吗?

Your starting point should be the Choosing an App Engine Environment guide, taking into consideration all your requirements.

您的出发点应该是选择一个应用程序引擎环境指南,考虑到您的所有需求。

And I have to connect it to PostgreSQL database.

我必须把它连接到PostgreSQL数据库。

This requirement makes the choice pretty easy. From Connecting from App Engine:

这个要求让选择变得非常简单。从App Engine连接:

This page provides language-specific links to informaton about how to set up a connection from an App Engine flexible environment application to a Cloud SQL for PostgreSQL instance.

这个页面提供了到informaton的特定语言链接,关于如何为PostgreSQL实例建立从应用引擎灵活环境应用程序到云SQL的连接。

Note: Connection from an App Engine standard environment application
to a PostgreSQL instance is not supported.

So flexible environment it is.

这是一个灵活的环境。

And how shall I install those libraries to the environment?

如何将这些库安装到环境中?

This dependends on the environment you use. What you tried was the standard env way.

这取决于您使用的环境。你尝试的是标准的env方法。

In the flexible environment dependencies are handled differently. From Dependencies:

在灵活的环境中,依赖关系的处理是不同的。从依赖关系:

The runtime looks for a requirements.txt file in your application's source directory and uses pip to install any dependencies before starting your application. For more information on declaring and managing packages, see Using Python Libraries

运行时查找需求。在启动应用程序之前,在应用程序的源目录中使用pip安装任何依赖项。有关声明和管理包的更多信息,请参见使用Python库

#1


1  

So, what environment shall I use? Standard or Flexible?

那么,我应该使用什么环境呢?标准或灵活吗?

Your starting point should be the Choosing an App Engine Environment guide, taking into consideration all your requirements.

您的出发点应该是选择一个应用程序引擎环境指南,考虑到您的所有需求。

And I have to connect it to PostgreSQL database.

我必须把它连接到PostgreSQL数据库。

This requirement makes the choice pretty easy. From Connecting from App Engine:

这个要求让选择变得非常简单。从App Engine连接:

This page provides language-specific links to informaton about how to set up a connection from an App Engine flexible environment application to a Cloud SQL for PostgreSQL instance.

这个页面提供了到informaton的特定语言链接,关于如何为PostgreSQL实例建立从应用引擎灵活环境应用程序到云SQL的连接。

Note: Connection from an App Engine standard environment application
to a PostgreSQL instance is not supported.

So flexible environment it is.

这是一个灵活的环境。

And how shall I install those libraries to the environment?

如何将这些库安装到环境中?

This dependends on the environment you use. What you tried was the standard env way.

这取决于您使用的环境。你尝试的是标准的env方法。

In the flexible environment dependencies are handled differently. From Dependencies:

在灵活的环境中,依赖关系的处理是不同的。从依赖关系:

The runtime looks for a requirements.txt file in your application's source directory and uses pip to install any dependencies before starting your application. For more information on declaring and managing packages, see Using Python Libraries

运行时查找需求。在启动应用程序之前,在应用程序的源目录中使用pip安装任何依赖项。有关声明和管理包的更多信息,请参见使用Python库