0

I am having an identical problem as here, and here, and here. However, I have attempted the answers given in each of those queries, to no avail.

In attempting to deploy an application, from the following command:

heroku run python manage.py migrate

ERROR

Traceback (most recent call last):
  File "manage.py", line 15, in <module>
    execute_from_command_line(sys.argv)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 224, in fetch_command
    klass = load_command_class(app_name, subcommand)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 36, in load_command_class
    module = import_module('%s.management.commands.%s' % (app_name, name))
  File "/app/.heroku/python/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 14, in <module>
    from django.db.migrations.autodetector import MigrationAutodetector
  File "/app/.heroku/python/lib/python3.6/site-packages/django/db/migrations/autodetector.py", line 11, in <module>
    from django.db.migrations.questioner import MigrationQuestioner
  File "/app/.heroku/python/lib/python3.6/site-packages/django/db/migrations/questioner.py", line 9, in <module>
    from .loader import MigrationLoader
  File "/app/.heroku/python/lib/python3.6/site-packages/django/db/migrations/loader.py", line 8, in <module>
    from django.db.migrations.recorder import MigrationRecorder
  File "/app/.heroku/python/lib/python3.6/site-packages/django/db/migrations/recorder.py", line 9, in <module>
    class MigrationRecorder:
  File "/app/.heroku/python/lib/python3.6/site-packages/django/db/migrations/recorder.py", line 22, in MigrationRecorder
    class Migration(models.Model):
  File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/base.py", line 87, in __new__
    app_config = apps.get_containing_app_config(module)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/apps/registry.py", line 249, in get_containing_app_config
    self.check_apps_ready()
  File "/app/.heroku/python/lib/python3.6/site-packages/django/apps/registry.py", line 131, in check_apps_ready
    settings.INSTALLED_APPS
  File "/app/.heroku/python/lib/python3.6/site-packages/django/conf/__init__.py", line 57, in __getattr__
    self._setup(name)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/conf/__init__.py", line 44, in _setup
    self._wrapped = Settings(settings_module)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/conf/__init__.py", line 107, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "/app/.heroku/python/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/app/mapping_data/settings.py", line 2, in <module>
    from decouple import config
ModuleNotFoundError: No module named 'decouple'

I suspect that the issue is caused by how I am deploying static. Especially since the command: python manage.py collectstatic returns the following error: FileNotFoundError: [Errno 2] No such file or directory at: '/mnt/project/static/'. Although, it could be an unrelated issue.

CODE

requirements.txt

python-decouple==3.1

settings.py

INSTALLED_APPS = [
    'django.contrib.staticfiles',
]

MIDDLEWARE = [
    'whitenoise.middleware.WhiteNoiseMiddleware',
]

PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
# The absolute path to the directory where collectstatic will collect static files for deployment
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
PROJECT_PATH = os.path.abspath(os.path.dirname(__name__))
# The URL to use when referring to static files (where they will be served from)
STATIC_URL = '/static/'
# Extra places for collectstatic to find static files.
STATICFILES_DIRS = [
    os.path.join(PROJECT_ROOT, 'static'),
]
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'
ROOT_URLCONF = 'mapping_data.urls'
STATICFILES_DIRS = (
    os.path.join(BASE_DIR, "static"),
)
MEDIA_ROOT = (
BASE_DIR
)

Pipfile

[[source]]

url = "https://pypi.python.org/simple"
verify_ssl = true
name = "pypi"

[packages]

django = "==2.1.2"

[dev-packages]

STRUCTURE

.git
__pycache__
htmlcov
mapping_data
     __pycache__
     static
         .keep
     __init__.py
     settings.py
     urls.py
     wsgi.py
mapping_twitter
     __pycache__
     migrations
     static
         css
             styles.css
         mapping_twitter
             histogram.png
     templates
     tests
     __init__.py
     admin.py
     apps.py
     forms.py
     models.py
     urls.py
     views.py
.coverage
.editorconfig
.env
.gitignore
db.sqlite3
ghostdriver.log
manage.py
Pipfile
Pipfile.lock
Procfile
requirements.txt
runtime.txt
Darcy
  • 575
  • 2
  • 8
  • 21
  • They seem to be separate issues. Can you post the contents of your `Pipfile`? – Selcuk Oct 24 '18 at 02:16
  • I have now included `Pipfile` – Darcy Oct 24 '18 at 02:37
  • 1
    Just a wild guess but it could be that the Heroku stack you are deploying on ignores `requirements.txt` when there is a `Pipfile`. Can you try adding `python-decouple = "==3.1"` under `[packages]`? – Selcuk Oct 24 '18 at 04:25
  • I followed your suggestion and still got the exact same error. I have included the full Traceback in the query above if it's of any assistance. – Darcy Oct 24 '18 at 05:54
  • 1
    Thanks @Selcuk you were, the issue was that, as was probably assumed in your comment, I didn't run `$ pipenv lock` after adding `python-decouple` to `[packages]` in the `Pipfile` – Darcy Oct 27 '18 at 02:29

1 Answers1

1

As stated by @Selcuk, the issue was the Pipfile ignored requirements.txt.

The steps required to convert from dependencies based on requirements.txt to pipenv are:

$ pip install pipenv

$ pipenv install -r requirements.txt

$ pipenv lock

Source

Darcy
  • 575
  • 2
  • 8
  • 21