2017-05-25 82 views
0

目前我正在試圖通過以下這個文檔發動我的Django的web應用程序GCP: hereImproperlyConfigured:對GCP錯誤加載psycopg2模塊

FYI:我使用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:[email protected]/DATABASE?host=/cloudsql/db:location:instance 

beta_settings: 
    cloud_sql_instances:db:location:instance 


skip_files: 
- ^(.*/)?#.*#$ 
- ^(.*/)?.*~$ 
- ^(.*/)?.*\.py[co]$ 
- ^(.*/)?.*/RCS/.*$ 
- ^(.*/)?\..*$ 
- ^env/.*$ 
由DB設置

終於在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] 

對此問題的解決方案非常感謝。謝謝。

+0

你的'requirements.txt'文件是什麼樣的? – themanatuf

+0

@themanatuf我編輯了我的帖子以包含我的requirements.txt和app.yaml。 – Mikebarson

+0

@themanatuf我也添加了一個appengine_config.py,但它給了我這個錯誤 「ValueError:virtualenv:無法訪問lib:沒有這樣的virtualenv或站點目錄」 – Mikebarson

回答

1

所以我解決了我的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/.*$ 
相關問題