【发布时间】:2017-10-26 06:53:03
【问题描述】:
目前我正在尝试按照以下文档将我的 django 网络应用程序启动到 GCP: here
仅供参考:我使用的是 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 错误进行一些研究后,我找到了一些答案here。
但这无济于事。
这是我的 requirements.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
这就是我的 app.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 上的 db 设置
# [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]
非常感谢此问题的解决方案。谢谢。
【问题讨论】:
-
您的
requirements.txt文件是什么样的? -
@themanatuf 我已经编辑了我的帖子以包含我的 requirements.txt 和 app.yaml。
-
@themanatuf 我还添加了一个 appengine_config.py 但它给了我这个错误“ValueError: virtualenv: cannot access lib: No such virtualenv or site directory”
标签: python django postgresql google-app-engine