简体   繁体   中英

Django Heroku Push Fails With Grep Usage Error After First Time

I have a simple Django app that I'm trying to deploy to Heroku.

I've followed the steps outlined in the Deploy your application to Heroku section here: https://devcenter.heroku.com/articles/deploying-python .

I'm working off of the branch heroku .

When I do git push heroku heroku:master , the first time it's able to push, everything succeeds and the app is deployed, however when I go to the app home page, I get a 503 error indicating that favicon.ico is missing. Then I make a commit with any small change, and try pushing again, and I get the following error:

Counting objects: 4, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 360 bytes | 0 bytes/s, done.
Total 4 (delta 3), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Python app detected
remote: -----> Installing requirements with pip
remote:        Usage: grep [OPTION]... PATTERN [FILE]...
remote:        Try 'grep --help' for more information.
remote:
remote: -----> $ python manage.py collectstatic --noinput
remote:        Traceback (most recent call last):
remote:          File "manage.py", line 22, in <module>
remote:            execute_from_command_line(sys.argv)
remote:          File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 363, in execute_from_command_line
remote:            utility.execute()
remote:          File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 337, in execute
remote:            django.setup()
remote:          File "/app/.heroku/python/lib/python2.7/site-packages/django/__init__.py", line 27, in setup
remote:            apps.populate(settings.INSTALLED_APPS)
remote:          File "/app/.heroku/python/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
remote:            app_config.import_models()
remote:          File "/app/.heroku/python/lib/python2.7/site-packages/django/apps/config.py", line 202, in import_models
remote:            self.models_module = import_module(models_module_name)
remote:          File "/app/.heroku/python/lib/python2.7/importlib/__init__.py", line 37, in import_module
remote:            __import__(name)
remote:          File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/auth/models.py", line 4, in <module>
remote:            from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
remote:          File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/auth/base_user.py", line 52, in <module>
remote:            class AbstractBaseUser(models.Model):
remote:          File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/base.py", line 124, in __new__
remote:            new_class.add_to_class('_meta', Options(meta, app_label))
remote:          File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/base.py", line 331, in add_to_class
remote:            value.contribute_to_class(cls, name)
remote:          File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/options.py", line 214, in contribute_to_class
remote:            self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
remote:          File "/app/.heroku/python/lib/python2.7/site-packages/django/db/__init__.py", line 33, in __getattr__
remote:            return getattr(connections[DEFAULT_DB_ALIAS], item)
remote:          File "/app/.heroku/python/lib/python2.7/site-packages/django/db/utils.py", line 211, in __getitem__
remote:            backend = load_backend(db['ENGINE'])
remote:          File "/app/.heroku/python/lib/python2.7/site-packages/django/db/utils.py", line 115, in load_backend
remote:            return import_module('%s.base' % backend_name)
remote:          File "/app/.heroku/python/lib/python2.7/importlib/__init__.py", line 37, in import_module
remote:            __import__(name)
remote:          File "/app/.heroku/python/lib/python2.7/site-packages/django/db/backends/postgresql/base.py", line 25, in <module>
remote:            raise ImproperlyConfigured("Error loading psycopg2 module: %s" % e)
remote:        django.core.exceptions.ImproperlyConfigured: Error loading psycopg2 module: No module named psycopg2
remote:
remote:  !     Error while running '$ python manage.py collectstatic --noinput'.
remote:        See traceback above for details.
remote:
remote:        You may need to update application code to resolve this error.
remote:        Or, you can disable collectstatic for this application:
remote:
remote:           $ heroku config:set DISABLE_COLLECTSTATIC=1
remote:
remote:        https://devcenter.heroku.com/articles/django-assets
remote:  !     Push rejected, failed to compile Python app.
remote:
remote:  !     Push failed
remote: Verifying deploy....
remote:
remote: !   Push rejected to stark-fortress-79930.

Things I've tried:

  • deleting and recreating the app, still happens consistently every second push
  • running heroku run bash , and running the commands manually, same error
  • adding psycopg2 to my requirements.txt
  • modifying and removing parts of my static files block in settings.py , here's what I have currently:

     STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles') STATIC_URL = '/static/' # Extra places for collectstatic to find static files. STATICFILES_DIRS = ( os.path.join(BASE_DIR, 'static'), ) 

I have favicon.ico inside of BASE_DIR/static .

Here's my requirements.txt :

beautifulsoup4==4.6.0
Cheetah==2.4.4
coverage==4.4.1
dj-database-url==0.4.2
Django==1.11.3
django-app-namespace-template-loader==0.4.1
django-blog-zinnia==0.18.1
django-contrib-comments==1.8.0
django-mptt==0.8.7
django-tagging==0.4.5
django-xmlrpc==0.1.7
gunicorn==19.7.1
mercurial==4.2.2
mots-vides==2015.5.11
olefile==0.44
Pillow==4.2.1
psycopg2==2.7.3
pyparsing==2.2.0
pytz==2017.2
PyYAML==3.11
regex==2017.7.11
six==1.10.0
virtualenv==14.0.6
whitenoise==3.3.0
zinnia-theme-bootstrap==0.5.1

Anyone able to shed some light on what I'm doing wrong?

Your problem is this line in the error output:

django.core.exceptions.ImproperlyConfigured: Error loading psycopg2 module: No module named psycopg2

Add psycopg2 to your requirements.txt . Some other part of your settings is setting up a Postgres database, and you must install the database driver package for that to work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM