简体   繁体   中英

python manage.py cause an ImportError: module not found

When trying to compile a heroku web app by running python manage.py runserver , I get the following error:

Unhandled exception in thread started by <function wrapper at 0x1046deb18>
Traceback (most recent call last):
  File "/Users/User/Desktop/App/App/lib/python2.7/site-packages/django/utils/autoreload.py", line 228, in wrapper
    fn(*args, **kwargs)
  File "/Users/User/Desktop/App/App/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 117, in inner_run
    autoreload.raise_last_exception()
  File "/Users/User/Desktop/App/App/lib/python2.7/site-packages/django/utils/autoreload.py", line 251, in raise_last_exception
    six.reraise(*_exception)
  File "/Users/User/Desktop/App/App/lib/python2.7/site-packages/django/utils/autoreload.py", line 228, in wrapper
    fn(*args, **kwargs)
  File "/Users/User/Desktop/App/App/lib/python2.7/site-packages/django/__init__.py", line 27, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/Users/User/Desktop/App/App/lib/python2.7/site-packages/django/apps/registry.py", line 85, in populate
    app_config = AppConfig.create(entry)
  File "/Users/User/Desktop/App/App/lib/python2.7/site-packages/django/apps/config.py", line 94, in create
    module = import_module(entry)
  File "/usr/local/Cellar/python/2.7.14/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
ImportError: No module named profiles

With the main issue being No module named profiles . Profiles is defined in app.py:

from __future__ import unicode_literals

from django.apps import AppConfig

class ProfilesConfig(AppConfig):
    name = 'profiles'

and is called in urls.py

from django.conf import settings
from django.conf.urls.static import static
from django.conf.urls import url
from django.contrib import admin

from profiles import views

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^$', views.home, name='home'),
    url(r'^one/', views.one, name='one'),
    url(r'^two/', views.two, name='two'),
    url(r'^three/', views.three, name='three'),
    url(r'^four/', views.four, name='four'),
    url(r'^five/', views.five, name='five'),
]

Profiles is also added in settings.py

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    # Disable Django's own staticfiles handling in favour of WhiteNoise, for
    # greater consistency between gunicorn and `./manage.py runserver`. See:
    # http://whitenoise.evans.io/en/stable/django.html#using-whitenoise-in-development
    'whitenoise.runserver_nostatic',
    'django.contrib.staticfiles',
    'profiles',
]

Profiles is a folder in my project directory that hosts the views.py file that I need for my urls to show up in Django. I've tried modifying the import statement, fiddling around with settings.py, but nothing is working and this is the error that shows up.

Project structure:

|—App
    |—App
        |—__init__.py
        |—__init__.pyc
        |—bin
        |— include
        |—lib
        |—profiles
            |—__init__.py
            |—__init__.pyc
            |— admin.py
            |— admin.pyc
            |— apps.py
            |— models.pyc
            |— templates
            |— tests.py
            |— views.py
            |— views.pyc
        |—static
        |—staticfiles
        |— urls.py
        |— urls.pyc
        |—wsgi.py
        |—wsgi.pyc
        |—db.sqlite3
        |—manage.py
        |—Procfile
        |—requirements.txt
        |—runtime.txt

Any idea as to why ImportError: No module named profiles is occuring?

The issue ended up being, as @dirkgroten correctly pointed out, that the structure of my Heroku directory was incorrect. I organized the directory using the structure described in this repo https://github.com/heroku/heroku-django-template and that resolved the problems.

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