簡體   English   中英

錯誤配置:在GCP上加載psycopg2模塊時出錯

[英]ImproperlyConfigured: Error loading psycopg2 module on GCP

目前,我正在嘗試通過遵循以下文檔將Django Web應用程序啟動到GCP: 這里

僅供參考:我正在使用Django 1.9和Python 2.7

使用gcloud app deploy我檢查了我的App Dashboard並看到了以下錯誤:

1)配置ImproperlyConfigured: Error loading psycopg2 module: No module named psycopg2

2) RuntimeError: populate() isn't reentrant

在對如何解決psycopg2錯誤進行了一些研究之后,我在這里找到了一些答案。

但這無濟於事。

這是我的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上的數據庫設置

# [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的問題。 事實證明,由於我使用的是標准App Engine環境,因此它不支持諸如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 install psycopg2修復的

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM