Heroku上的Python入门 - 在本地运行app步骤问题

时间:2015-06-14 22:41:40

标签: python django postgresql heroku

我正在关注" Getting Started with Python on Heroku"官方教程。我认为该教程基本上是关于设置Django Hello World,尽管我还没有看到结果。

这些步骤有效:

   $ git clone https://github.com/heroku/python-getting-started.git
   $ heroku create
   $ git push heroku master

最后一个命令的输出(在我看来是重要部分):

...
remote: -----> Python app detected
remote: -----> Installing runtime (python-2.7.9)
remote: -----> Installing dependencies with pip
remote:        Collecting dj-database-url==0.3.0 (from -r requirements.txt (line 1))
remote:          Downloading dj_database_url-0.3.0-py2.py3-none-any.whl
remote:        Collecting Django==1.8.1 (from -r requirements.txt (line 2))
remote:          Downloading Django-1.8.1-py2.py3-none-any.whl (6.2MB)
remote:        Collecting django-postgrespool==0.3.0 (from -r requirements.txt (line 3))
remote:          Downloading django-postgrespool-0.3.0.tar.gz
remote:        Collecting gunicorn==19.3.0 (from -r requirements.txt (line 4))
remote:          Downloading gunicorn-19.3.0-py2.py3-none-any.whl (110kB)
remote:        Collecting psycopg2==2.6 (from -r requirements.txt (line 5))
remote:          Downloading psycopg2-2.6.tar.gz (367kB)
remote:        Collecting SQLAlchemy==1.0.4 (from -r requirements.txt (line 6))
remote:          Downloading SQLAlchemy-1.0.4.tar.gz (4.6MB)
remote:        Collecting whitenoise==1.0.6 (from -r requirements.txt (line 7))
remote:          Downloading whitenoise-1.0.6-py2.py3-none-any.whl
remote:        Installing collected packages: dj-database-url, Django, psycopg2, SQLAlchemy, django-postgrespool, gunicorn, whitenoise
remote:          Running setup.py install for psycopg2
remote:          Running setup.py install for SQLAlchemy
remote:          Running setup.py install for django-postgrespool
remote:        Successfully installed Django-1.8.1 SQLAlchemy-1.0.4 dj-database-url-0.3.0 django-postgrespool-0.3.0 gunicorn-19.3.0 psycopg2-2.6 whitenoise-1.0.6
...

进一步的命令:

$ heroku ps:scale web=1
$ heroku open

然后使用以下行定义Procfile:

web: gunicorn gettingstarted.wsgi --log-file -

然后创建了一个virtualenv(尝试使用Python 2.7.6。和3.4.2):

$ virtual venv
$ source venv/bin/activate
$ pip install -r requirements.txt --allow-all-external

第一次我遇到了psycopg2-2.6的问题,然后我相信我成功安装了。以下是所有要求: - dj-database-url == 0.3.0 - Django == 1.8.1 - django-postgrespool == 0.3.0 - gunicorn == 19.3.0 - psycopg2 == 2.6 - SQLAlchemy == 1.0.4 - whitenoise == 1.0.6

这就是我要去的地方:

foreman start web

从此项目结构的主目录调用:

python-getting-started/
├── Procfile
├── Procfile.windows
├── README.md
├── gettingstarted
│   ├── __init__.py
│   ├── __pycache__
│   │   ├── __init__.cpython-34.pyc
│   │   ├── settings.cpython-34.pyc
│   │   └── wsgi.cpython-34.pyc
│   ├── settings.py
│   ├── static
│   │   └── humans.txt
│   ├── urls.py
│   └── wsgi.py
├── hello
│   ├── __init__.py
│   ├── __pycache__
│   │   └── __init__.cpython-34.pyc
│   ├── admin.py
│   ├── models.py
│   ├── templates
│   │   └── db.html
│   ├── tests.py
│   └── views.py
├── manage.py
├── requirements.txt
└── runtime.txt

最后一个命令的输出是:

23:35:07 web.1  | started with pid 6296
23:35:07 web.1  | [2015-06-14 23:35:07 +0100] [6296] [INFO] Starting gunicorn 19.3.0
23:35:07 web.1  | [2015-06-14 23:35:07 +0100] [6296] [INFO] Listening at: http://0.0.0.0:5000 (6296)
23:35:07 web.1  | [2015-06-14 23:35:07 +0100] [6296] [INFO] Using worker: sync
23:35:07 web.1  | [2015-06-14 23:35:07 +0100] [6299] [INFO] Booting worker with pid: 6299
23:35:07 web.1  | [2015-06-14 22:35:07 +0000] [6299] [ERROR] Exception in worker process:
23:35:07 web.1  | Traceback (most recent call last):
23:35:07 web.1  |   File "/Users/janosbana/developer/playground/Python/heroku/python-getting-started/venv/lib/python3.4/site-packages/django/db/utils.py", line 111, in load_backend
23:35:07 web.1  |     return import_module('%s.base' % backend_name)
23:35:07 web.1  |   File "/Users/janosbana/developer/playground/Python/heroku/python-getting-started/venv/lib/python3.4/importlib/__init__.py", line 109, in import_module
23:35:07 web.1  |     return _bootstrap._gcd_import(name[level:], package, level)
23:35:07 web.1  |   File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
23:35:07 web.1  |   File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
23:35:07 web.1  |   File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
23:35:07 web.1  |   File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
23:35:07 web.1  |   File "<frozen importlib._bootstrap>", line 1129, in _exec
23:35:07 web.1  |   File "<frozen importlib._bootstrap>", line 1471, in exec_module
23:35:07 web.1  |   File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
23:35:07 web.1  |   File "/Users/janosbana/developer/playground/Python/heroku/python-getting-started/venv/lib/python3.4/site-packages/django_postgrespool/base.py", line 8, in <module>
23:35:07 web.1  |     from psycopg2 import InterfaceError, ProgrammingError, OperationalError
23:35:07 web.1  |   File "/Users/janosbana/developer/playground/Python/heroku/python-getting-started/venv/lib/python3.4/site-packages/psycopg2/__init__.py", line 50, in <module>
23:35:07 web.1  |     from psycopg2._psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID
23:35:07 web.1  | ImportError: dlopen(/Users/janosbana/developer/playground/Python/heroku/python-getting-started/venv/lib/python3.4/site-packages/psycopg2/_psycopg.so, 2): Library not loaded: libssl.1.0.0.dylib
23:35:07 web.1  |   Referenced from: /Users/janosbana/developer/playground/Python/heroku/python-getting-started/venv/lib/python3.4/site-packages/psycopg2/_psycopg.so
23:35:07 web.1  |   Reason: image not found
23:35:07 web.1  |
23:35:07 web.1  | During handling of the above exception, another exception occurred:
23:35:07 web.1  |
23:35:07 web.1  | Traceback (most recent call last):
23:35:07 web.1  |   File "/Users/janosbana/developer/playground/Python/heroku/python-getting-started/venv/lib/python3.4/site-packages/gunicorn/arbiter.py", line 507, in spawn_worker
23:35:07 web.1  |     worker.init_process()
23:35:07 web.1  |   File "/Users/janosbana/developer/playground/Python/heroku/python-getting-started/venv/lib/python3.4/site-packages/gunicorn/workers/base.py", line 118, in init_process
23:35:07 web.1  |     self.wsgi = self.app.wsgi()
23:35:07 web.1  |   File "/Users/janosbana/developer/playground/Python/heroku/python-getting-started/venv/lib/python3.4/site-packages/gunicorn/app/base.py", line 67, in wsgi
23:35:07 web.1  |     self.callable = self.load()
23:35:07 web.1  |   File "/Users/janosbana/developer/playground/Python/heroku/python-getting-started/venv/lib/python3.4/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
23:35:07 web.1  |     return self.load_wsgiapp()
23:35:07 web.1  |   File "/Users/janosbana/developer/playground/Python/heroku/python-getting-started/venv/lib/python3.4/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
23:35:07 web.1  |     return util.import_app(self.app_uri)
23:35:07 web.1  |   File "/Users/janosbana/developer/playground/Python/heroku/python-getting-started/venv/lib/python3.4/site-packages/gunicorn/util.py", line 355, in import_app
23:35:07 web.1  |     __import__(module)
23:35:07 web.1  |   File "/Users/janosbana/developer/playground/Python/heroku/python-getting-started/gettingstarted/wsgi.py", line 16, in <module>
23:35:07 web.1  |     application = get_wsgi_application()
23:35:07 web.1  |   File "/Users/janosbana/developer/playground/Python/heroku/python-getting-started/venv/lib/python3.4/site-packages/django/core/wsgi.py", line 14, in get_wsgi_application
23:35:07 web.1  |     django.setup()
23:35:07 web.1  |   File "/Users/janosbana/developer/playground/Python/heroku/python-getting-started/venv/lib/python3.4/site-packages/django/__init__.py", line 18, in setup
23:35:07 web.1  |     apps.populate(settings.INSTALLED_APPS)
23:35:07 web.1  |   File "/Users/janosbana/developer/playground/Python/heroku/python-getting-started/venv/lib/python3.4/site-packages/django/apps/registry.py", line 108, in populate
23:35:07 web.1  |     app_config.import_models(all_models)
23:35:07 web.1  |   File "/Users/janosbana/developer/playground/Python/heroku/python-getting-started/venv/lib/python3.4/site-packages/django/apps/config.py", line 198, in import_models
23:35:07 web.1  |     self.models_module = import_module(models_module_name)
23:35:07 web.1  |   File "/Users/janosbana/developer/playground/Python/heroku/python-getting-started/venv/lib/python3.4/importlib/__init__.py", line 109, in import_module
23:35:07 web.1  |     return _bootstrap._gcd_import(name[level:], package, level)
23:35:07 web.1  |   File "/Users/janosbana/developer/playground/Python/heroku/python-getting-started/venv/lib/python3.4/site-packages/django/contrib/auth/models.py", line 41, in <module>
23:35:07 web.1  |     class Permission(models.Model):
23:35:07 web.1  |   File "/Users/janosbana/developer/playground/Python/heroku/python-getting-started/venv/lib/python3.4/site-packages/django/db/models/base.py", line 139, in __new__
23:35:07 web.1  |     new_class.add_to_class('_meta', Options(meta, **kwargs))
23:35:07 web.1  |   File "/Users/janosbana/developer/playground/Python/heroku/python-getting-started/venv/lib/python3.4/site-packages/django/db/models/base.py", line 324, in add_to_class
23:35:07 web.1  |     value.contribute_to_class(cls, name)
23:35:07 web.1  |   File "/Users/janosbana/developer/playground/Python/heroku/python-getting-started/venv/lib/python3.4/site-packages/django/db/models/options.py", line 250, in contribute_to_class
23:35:07 web.1  |     self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
23:35:07 web.1  |   File "/Users/janosbana/developer/playground/Python/heroku/python-getting-started/venv/lib/python3.4/site-packages/django/db/__init__.py", line 36, in __getattr__
23:35:07 web.1  |     return getattr(connections[DEFAULT_DB_ALIAS], item)
23:35:07 web.1  |   File "/Users/janosbana/developer/playground/Python/heroku/python-getting-started/venv/lib/python3.4/site-packages/django/db/utils.py", line 240, in __getitem__
23:35:07 web.1  |     backend = load_backend(db['ENGINE'])
23:35:07 web.1  |   File "/Users/janosbana/developer/playground/Python/heroku/python-getting-started/venv/lib/python3.4/site-packages/django/db/utils.py", line 129, in load_backend
23:35:07 web.1  |     raise ImproperlyConfigured(error_msg)
23:35:07 web.1  | django.core.exceptions.ImproperlyConfigured: 'django_postgrespool' isn't an available database backend.
23:35:07 web.1  | Try using 'django.db.backends.XXX', where XXX is one of:
23:35:07 web.1  |     'base', 'mysql', 'oracle', 'postgresql_psycopg2', 'sqlite3'
23:35:07 web.1  | Error was: dlopen(/Users/janosbana/developer/playground/Python/heroku/python-getting-started/venv/lib/python3.4/site-packages/psycopg2/_psycopg.so, 2): Library not loaded: libssl.1.0.0.dylib
23:35:07 web.1  |   Referenced from: /Users/janosbana/developer/playground/Python/heroku/python-getting-started/venv/lib/python3.4/site-packages/psycopg2/_psycopg.so
23:35:07 web.1  |   Reason: image not found
23:35:07 web.1  | Traceback (most recent call last):
23:35:07 web.1  |   File "/Users/janosbana/developer/playground/Python/heroku/python-getting-started/venv/lib/python3.4/site-packages/django/db/utils.py", line 111, in load_backend
23:35:07 web.1  |     return import_module('%s.base' % backend_name)
23:35:07 web.1  |   File "/Users/janosbana/developer/playground/Python/heroku/python-getting-started/venv/lib/python3.4/importlib/__init__.py", line 109, in import_module
23:35:07 web.1  |     return _bootstrap._gcd_import(name[level:], package, level)
23:35:07 web.1  |   File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
23:35:07 web.1  |   File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
23:35:07 web.1  |   File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
23:35:07 web.1  |   File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
23:35:07 web.1  |   File "<frozen importlib._bootstrap>", line 1129, in _exec
23:35:07 web.1  |   File "<frozen importlib._bootstrap>", line 1471, in exec_module
23:35:07 web.1  |   File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
23:35:07 web.1  |   File "/Users/janosbana/developer/playground/Python/heroku/python-getting-started/venv/lib/python3.4/site-packages/django_postgrespool/base.py", line 8, in <module>
23:35:07 web.1  |     from psycopg2 import InterfaceError, ProgrammingError, OperationalError
23:35:07 web.1  |   File "/Users/janosbana/developer/playground/Python/heroku/python-getting-started/venv/lib/python3.4/site-packages/psycopg2/__init__.py", line 50, in <module>
23:35:07 web.1  |     from psycopg2._psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID
23:35:07 web.1  | ImportError: dlopen(/Users/janosbana/developer/playground/Python/heroku/python-getting-started/venv/lib/python3.4/site-packages/psycopg2/_psycopg.so, 2): Library not loaded: libssl.1.0.0.dylib
23:35:07 web.1  |   Referenced from: /Users/janosbana/developer/playground/Python/heroku/python-getting-started/venv/lib/python3.4/site-packages/psycopg2/_psycopg.so
23:35:07 web.1  |   Reason: image not found
23:35:07 web.1  |
23:35:07 web.1  | During handling of the above exception, another exception occurred:
23:35:07 web.1  |
23:35:07 web.1  | Traceback (most recent call last):
23:35:07 web.1  |   File "/Users/janosbana/developer/playground/Python/heroku/python-getting-started/venv/lib/python3.4/site-packages/gunicorn/arbiter.py", line 507, in spawn_worker
23:35:07 web.1  |     worker.init_process()
23:35:07 web.1  |   File "/Users/janosbana/developer/playground/Python/heroku/python-getting-started/venv/lib/python3.4/site-packages/gunicorn/workers/base.py", line 118, in init_process
23:35:07 web.1  |     self.wsgi = self.app.wsgi()
23:35:07 web.1  |   File "/Users/janosbana/developer/playground/Python/heroku/python-getting-started/venv/lib/python3.4/site-packages/gunicorn/app/base.py", line 67, in wsgi
23:35:07 web.1  |     self.callable = self.load()
23:35:07 web.1  |   File "/Users/janosbana/developer/playground/Python/heroku/python-getting-started/venv/lib/python3.4/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
23:35:07 web.1  |     return self.load_wsgiapp()
23:35:07 web.1  |   File "/Users/janosbana/developer/playground/Python/heroku/python-getting-started/venv/lib/python3.4/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
23:35:07 web.1  |     return util.import_app(self.app_uri)
23:35:07 web.1  |   File "/Users/janosbana/developer/playground/Python/heroku/python-getting-started/venv/lib/python3.4/site-packages/gunicorn/util.py", line 355, in import_app
23:35:07 web.1  |     __import__(module)
23:35:07 web.1  |   File "/Users/janosbana/developer/playground/Python/heroku/python-getting-started/gettingstarted/wsgi.py", line 16, in <module>
23:35:07 web.1  |     application = get_wsgi_application()
23:35:07 web.1  |   File "/Users/janosbana/developer/playground/Python/heroku/python-getting-started/venv/lib/python3.4/site-packages/django/core/wsgi.py", line 14, in get_wsgi_application
23:35:07 web.1  |     django.setup()
23:35:07 web.1  |   File "/Users/janosbana/developer/playground/Python/heroku/python-getting-started/venv/lib/python3.4/site-packages/django/__init__.py", line 18, in setup
23:35:07 web.1  |     apps.populate(settings.INSTALLED_APPS)
23:35:07 web.1  |   File "/Users/janosbana/developer/playground/Python/heroku/python-getting-started/venv/lib/python3.4/site-packages/django/apps/registry.py", line 108, in populate
23:35:07 web.1  |     app_config.import_models(all_models)
23:35:07 web.1  |   File "/Users/janosbana/developer/playground/Python/heroku/python-getting-started/venv/lib/python3.4/site-packages/django/apps/config.py", line 198, in import_models
23:35:07 web.1  |     self.models_module = import_module(models_module_name)
23:35:07 web.1  |   File "/Users/janosbana/developer/playground/Python/heroku/python-getting-started/venv/lib/python3.4/importlib/__init__.py", line 109, in import_module
23:35:07 web.1  |     return _bootstrap._gcd_import(name[level:], package, level)
23:35:07 web.1  |   File "/Users/janosbana/developer/playground/Python/heroku/python-getting-started/venv/lib/python3.4/site-packages/django/contrib/auth/models.py", line 41, in <module>
23:35:07 web.1  |     class Permission(models.Model):
23:35:07 web.1  |   File "/Users/janosbana/developer/playground/Python/heroku/python-getting-started/venv/lib/python3.4/site-packages/django/db/models/base.py", line 139, in __new__
23:35:07 web.1  |     new_class.add_to_class('_meta', Options(meta, **kwargs))
23:35:07 web.1  |   File "/Users/janosbana/developer/playground/Python/heroku/python-getting-started/venv/lib/python3.4/site-packages/django/db/models/base.py", line 324, in add_to_class
23:35:07 web.1  |     value.contribute_to_class(cls, name)
23:35:07 web.1  |   File "/Users/janosbana/developer/playground/Python/heroku/python-getting-started/venv/lib/python3.4/site-packages/django/db/models/options.py", line 250, in contribute_to_class
23:35:07 web.1  |     self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
23:35:07 web.1  |   File "/Users/janosbana/developer/playground/Python/heroku/python-getting-started/venv/lib/python3.4/site-packages/django/db/__init__.py", line 36, in __getattr__
23:35:07 web.1  |     return getattr(connections[DEFAULT_DB_ALIAS], item)
23:35:07 web.1  |   File "/Users/janosbana/developer/playground/Python/heroku/python-getting-started/venv/lib/python3.4/site-packages/django/db/utils.py", line 240, in __getitem__
23:35:07 web.1  |     backend = load_backend(db['ENGINE'])
23:35:07 web.1  |   File "/Users/janosbana/developer/playground/Python/heroku/python-getting-started/venv/lib/python3.4/site-packages/django/db/utils.py", line 129, in load_backend
23:35:07 web.1  |     raise ImproperlyConfigured(error_msg)
23:35:07 web.1  | django.core.exceptions.ImproperlyConfigured: 'django_postgrespool' isn't an available database backend.
23:35:07 web.1  | Try using 'django.db.backends.XXX', where XXX is one of:
23:35:07 web.1  |     'base', 'mysql', 'oracle', 'postgresql_psycopg2', 'sqlite3'
23:35:07 web.1  | Error was: dlopen(/Users/janosbana/developer/playground/Python/heroku/python-getting-started/venv/lib/python3.4/site-packages/psycopg2/_psycopg.so, 2): Library not loaded: libssl.1.0.0.dylib
23:35:07 web.1  |   Referenced from: /Users/janosbana/developer/playground/Python/heroku/python-getting-started/venv/lib/python3.4/site-packages/psycopg2/_psycopg.so
23:35:07 web.1  |   Reason: image not found
23:35:07 web.1  | [2015-06-14 22:35:07 +0000] [6299] [INFO] Worker exiting (pid: 6299)
23:35:07 web.1  | [2015-06-14 23:35:07 +0100] [6296] [INFO] Shutting down: Master
23:35:07 web.1  | [2015-06-14 23:35:07 +0100] [6296] [INFO] Reason: Worker failed to boot.
23:35:07 web.1  | exited with code 3
23:35:07 system | sending SIGTERM to all processes

请注意我在OSX Yosemite上安装了 postgres(PostgreSQL)9.4.4

我认为数据库配置存在一些问题,但我对此非常陌生,并且很难对调试日志中发生的情况进行调查。 我在网上搜索试图找到类似情况的最后一个命令的输出,但是我没有发现任何与我的完全相同的性质。

有没有人经历过类似的事情?请帮忙弄清楚如何处理它。

修改

自问这个问题以来,Heroku教程中又出现了一个步骤。

Run the app locally步骤现在具有以下命令:

$ python manage.py collectstatic

这一行是在我被卡住的步骤之前添加的:

$ foreman start web

1 个答案:

答案 0 :(得分:3)

根据您的错误django.core.exceptions.ImproperlyConfigured: 'django_postgrespool' isn't an available database backend.,您的DATABASE设置似乎配置不正确。

在您的设置文件中,由于您正在使用postgresql,请确保将数据库ENGINE设置为'django.db.backends.postgresql_psycopg2'。请参阅数据库docs和数据库引擎docs