目前我正在尝试按照以下文档将我的 django Web 应用程序启动到 GCP:这里
仅供参考:我正在使用Django 1.9和Python 2.7
使用 gcloud app deploy
部署应用程序后,我检查了我的应用程序仪表板并看到了以下错误:
1( ImproperlyConfigured: Error loading psycopg2 module: No module named psycopg2
2( RuntimeError: populate() isn't reentrant
在对如何修复psycopg2错误进行了一些研究后,我在这里找到了一些答案。
但这无济于事。
以下是我的要求.txt
psycopg2==2.7.1
Flask==0.12
Flask-SQLAlchemy==2.2
gunicorn==19.7.0
PyMySQL==0.7.10
django==1.9
django-imagekit
pillow
pyexcel
pyexcel_xls
django_excel
xlsxwriter
python-dateutil
django-mail-templated
djangorestframework
django-cors-headers
django-extra-fields
pytz
numpy
reportlab
xhtml2pdf
html5lib==1.0b8
pypdf
这就是我的应用程序.yaml 中的内容
runtime: python27
api_version: 1
threadsafe: yes
handlers:
- url: /static
static_dir: static/
- url: .*
script: root.wsgi.application
libraries:
- name: MySQLdb
version: 1.2.5
- name: django
version: 1.9
env_variables:
# Replace user, password, database, and instance connection name with the values obtained
# when configuring your Cloud SQL instance.
SQLALCHEMY_DATABASE_URI: >-
postgresql+psycopg2://postgres:db_password@/DATABASE?host=/cloudsql/db:location:instance
beta_settings:
cloud_sql_instances:db:location:instance
skip_files:
- ^(.*/)?#.*#$
- ^(.*/)?.*~$
- ^(.*/)?.*.py[co]$
- ^(.*/)?.*/RCS/.*$
- ^(.*/)?..*$
- ^env/.*$
最后通过 settings.py 上的数据库设置
# [START db_setup]
if os.getenv('SERVER_SOFTWARE', '').startswith('Google App Engine'):
# Running on production App Engine, so connect to Google Cloud SQL using
# the unix socket at /cloudsql/<your-cloudsql-connection string>
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'HOST': '/cloudsql/db_name:location:instance_name',
'NAME': 'db_name',
'USER': 'user_name',
'PASSWORD': 'db_password',
}
}
else:
from .local_settings import *
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': name,
'USER': user,
'PASSWORD': password,
'HOST' : host,
'PORT' : '',
}
}
# [END db_setup]
非常感谢这个问题的解决方案。谢谢。
所以我解决了关于我的postgreSQL的问题。事实证明,由于我使用的是标准应用程序引擎环境,因此它不支持像postgreSQL这样的第三方应用程序。所以我不得不切换到 Flex 环境,这非常容易。我刚刚将我的app.yaml更改为:
# [START runtime]
runtime: python
env: flex
entrypoint: gunicorn -b :$PORT myproject.wsgi
beta_settings:
cloud_sql_instances: project:location:instance_name
runtime_config:
python_version: 2
# [END runtime]
# Google App Engine limits application deployments to 10,000 uploaded files per
# version. The skip_files section allows us to skip virtual environment files
# to meet this requirement. The first 5 are the default regular expressions to
# skip, while the last one is for all env/ files.
skip_files:
- ^(.*/)?#.*#$
- ^(.*/)?.*~$
- ^(.*/)?.*.py[co]$
- ^(.*/)?.*/RCS/.*$
- ^(.*/)?..*$
- ^env/.*$
在我的情况下,它是通过执行 pip 安装 psycopg2 来修复