问题
Today all my Python/Django applications on Heroku stopped working.
The logs for all of them show the same issue. When trying to restart/build, the error log is as shown below.
I have tried rebuilding the projects in a new local virtual environment, and they work fine locally. However, when pushing them to Heroku, they encounter this ImportError and refuse to deploy.
Similarly, when I try to restart the existing applications, I see the same error logged prior to the instance crashing.
Please let me know if there is any other information I can provide.
Error log:
2014-06-03T22:30:05.293788+00:00 heroku[web.1]: State changed from crashed to starting
2014-06-03T22:30:11.509350+00:00 app[web.1]: Traceback (most recent call last):
2014-06-03T22:30:11.509438+00:00 app[web.1]: File "bluewaterads/manage.py", line 22, in <module>
2014-06-03T22:30:11.509536+00:00 app[web.1]: from django.core.management import execute_manager
2014-06-03T22:30:11.509589+00:00 app[web.1]: File "/app/.heroku/venv/lib/python2.7/site-packages/django/core/management/__init__.py", line 8, in <module>
2014-06-03T22:30:11.509644+00:00 app[web.1]: from django.core.management.base import BaseCommand, CommandError, handle_default_options
2014-06-03T22:30:11.509667+00:00 app[web.1]: File "/app/.heroku/venv/lib/python2.7/site-packages/django/core/management/base.py", line 16, in <module>
2014-06-03T22:30:11.509707+00:00 app[web.1]: from django.utils.encoding import smart_str
2014-06-03T22:30:11.509727+00:00 app[web.1]: File "/app/.heroku/venv/lib/python2.7/site-packages/django/utils/encoding.py", line 2, in <module>
2014-06-03T22:30:11.509796+00:00 app[web.1]: import urllib
2014-06-03T22:30:11.509824+00:00 app[web.1]: File "/usr/local/lib/python2.7/urllib.py", line 26, in <module>
2014-06-03T22:30:11.509869+00:00 app[web.1]: import socket
2014-06-03T22:30:11.509886+00:00 app[web.1]: File "/usr/local/lib/python2.7/socket.py", line 47, in <module>
2014-06-03T22:30:11.509919+00:00 app[web.1]: import _socket
2014-06-03T22:30:11.509954+00:00 app[web.1]: ImportError: /app/.heroku/venv/lib/python2.7/lib-dynload/_socket.so: undefined symbol: _PyInt_AsInt
2014-06-03T22:30:13.014774+00:00 heroku[web.1]: State changed from starting to crashed
2014-06-03T22:30:10.241602+00:00 heroku[web.1]: Starting process with command `python bluewaterads/manage.py run_gunicorn 0.0.0.0:33709 -w 4`
2014-06-03T22:30:13.015823+00:00 heroku[web.1]: Process exited with status 1
Requirements.txt:
Django==1.4.1
Mezzanine==1.2.4.1
Pillow==1.7.7
South==0.7.6
bleach==1.1.5
boto==2.5.2
dj-database-url==0.2.1
django-appconf==0.5
django-compressor==1.2
django-s3-storages-utils==0.1.0
django-storages==1.1.5
filebrowser-safe==0.2.11
grappelli-safe==0.2.9
gunicorn==0.14.6
html5lib==0.95
psycopg2==2.4.5
pytz==2012d
Procfile:
web: python bluewaterads/manage.py run_gunicorn 0.0.0.0:$PORT -w 4
回答1:
When deploying your application, if at runtime the updated python-2.7.7 is not being used.
Try purging the repo cache.
Install this:
heroku plugins:install https://github.com/heroku/heroku-repo.git
Then run this command:
heroku repo:purge_cache -a appname
Then deploy your application.
More info here: Heroku-repo
回答2:
Add runtime.txt
with python-2.7.7
to your project root and redeploy.
Heroku has just updated the runtime to python-2.7.7. This article was updated yesterday: https://devcenter.heroku.com/articles/python-runtimes
[EDITED]: This forces Heroku to rebuild the virtualenv from scratch. You can specify any runtime.
回答3:
Are you using the default Python buildpack? Heroku is in the process of updating the Stack image, and especially if you're not using a current buildpack, there may be incompatibilities.
To see if you're using a default buildpack, run
$ heroku config | grep BUILDPACK_URL
Please contact Heroku support if you think this might be the cause.
回答4:
I had the same thing happen to my heroku app, and after trying a million things I ended up fixing it by upgrading all of my packages including django, adding the wsgi.py file according to the django/heroku tutorial, and changing my procfile to this:
web: gunicorn app.wsgi --pythonpath app --log-file -
The pythonpath setting is important because I had a ton of import errors and internal server errors because gunicorn no longer had the right path to my app.
来源:https://stackoverflow.com/questions/24026377/heroku-python-django-applications-all-simultaneously-developed-importerror