LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Need help with old django: ImportError: No module named app (https://www.linuxquestions.org/questions/programming-9/need-help-with-old-django-importerror-no-module-named-app-4175699056/)

maschelsea 08-12-2021 01:10 AM

Need help with old django: ImportError: No module named app
 
I'm taking yet another course at Skillshare. Skillshare seems to be a place to dump your programming courses. I doubt the teacher is actually available, otherwise I'd ask her.

My current issue (I suspect) is because I am using old Python (2.7.17) with an old Django (1.11.13) (version provided by the teacher in a download form) I have done what I'm trying to do in this course with other newer versions of Django (Django 2.x) But I'm having enormous difficulty finding any infomation on my particular error. When I took programming in college, it wasn't this hard. Nothing was. But then I didn't use it everyday for ten years. Then for ten years after that I didn't use it at all. It's rather ironic. I'm thinking of redoing my old COBOL final project in python. That is, in Python 3. But that's neither here nor there.

My issue is this:
Code:

michael@caitlyn Skeleton Project (django-admin) $ python manage.py runserver
Unhandled exception in thread started by <function wrapper at 0x7efc5297e6d0>
Traceback (most recent call last):
  File "/usr/lib64/python2.7/site-packages/Django-1.11.13-py2.7.egg/django/utils/autoreload.py", line 228, in wrapper
    fn(*args, **kwargs)
  File "/usr/lib64/python2.7/site-packages/Django-1.11.13-py2.7.egg/django/core/management/commands/runserver.py", line 116, in inner_run
    autoreload.raise_last_exception()
  File "/usr/lib64/python2.7/site-packages/Django-1.11.13-py2.7.egg/django/utils/autoreload.py", line 251, in raise_last_exception
    six.reraise(*_exception)
  File "/usr/lib64/python2.7/site-packages/Django-1.11.13-py2.7.egg/django/utils/autoreload.py", line 228, in wrapper
    fn(*args, **kwargs)
  File "/usr/lib64/python2.7/site-packages/Django-1.11.13-py2.7.egg/django/__init__.py", line 27, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/usr/lib64/python2.7/site-packages/Django-1.11.13-py2.7.egg/django/apps/registry.py", line 85, in populate
    app_config = AppConfig.create(entry)
  File "/usr/lib64/python2.7/site-packages/Django-1.11.13-py2.7.egg/django/apps/config.py", line 120, in create
    mod = import_module(mod_path)
  File "/usr/lib64/python2.7/importlib/__init__.py", line 37, in import_module
ImportError: No module named app

One of my many Python teachers said that to be taken seriously as a programmer, I need to learn to look up the answers on StackOverflow and other such sites. I looked up this problem on StackOverflow and someone there was having a problem that seemed similar to mine said that I should create a file named app.py in the same directory that __init__.py is in, so I did. It didn't help. There IS no __init__.py. There's __init__pyc and __init__pyo, both of them binary files. With my app.py file, which I made with touch:
Code:

root@caitlyn:~# ls /usr/lib64/python2.7/importlib/         
__init__.pyc  __init__.pyo  app.py
root@caitlyn:~# file /usr/lib64/python2.7/importlib/__init__.pyc
/usr/lib64/python2.7/importlib/__init__.pyc: python 2.7 byte-compiled
root@caitlyn:~# file __init__.pyo
__init__.pyo: cannot open `__init__.pyo' (No such file or directory)
root@caitlyn:~# file /usr/lib64/python2.7/importlib/__init__.pyo
/usr/lib64/python2.7/importlib/__init__.pyo: python 2.7 byte-compiled
root@caitlyn:~#

Any help with resolving this issue will be appreciated. Thank you in advance for any advice you can offer.

shruggy 08-12-2021 05:15 AM

Could it be a typo somewhere in the script? Like app instead of apps? You probably have something like
Code:

from django.apps import apps

boughtonp 08-12-2021 10:27 AM

Quote:

Originally Posted by maschelsea (Post 6274584)
I doubt the teacher is actually available, otherwise I'd ask her.

"Doubt"? You mean you can't be bothered to try.


Quote:

My issue is this:
Code:

michael@caitlyn Skeleton Project (django-admin) $ python manage.py runserver
<snip>
ImportError: No module named app


Python cannot find the "app" module. There are a number of potential reasons for this error.

The course teacher will know whether that module should exist (and where it should be), whether it should have been created earlier, etc - and thus can tell you very quickly whether it's a typo, path issue, or something else.

Without even a reference to the course, all anybody here can do is make guesses.



Quote:

One of my many Python teachers said that to be taken seriously as a programmer, I need to learn to look up the answers on Stack Overflow and other such sites.
Being able to search effectively is vital, but programmers who only look up answers on Stack Overflow are ones that aren't taken seriously.

Good programmers understand what errors are saying and will look for explanations not answers - those can come from many websites.

Generally the Stack Overflow responses worth considering are the ones that explain why the error is occurring and link to relevant documentation - i.e. those that assist with understanding - but a large number of them are written by mediocre programmers with a limited grasp on what they're responding to.


Quote:

I looked up this problem on StackOverflow and someone there was having a problem that seemed similar to mine said that I should create a file named app.py in the same directory that __init__.py is in, so I did. It didn't help. There IS no __init__.py. There's __init__pyc and __init__pyo, both of them binary files.
If you don't understand what __init__.py is and which directories it exists in, you should read the Python documentation on modules.

Once you have read that, you may understand why creating app.py in one of Python's system directories was never going to solve your problem (and is a misunderstanding of whatever the issue on StackOverflow was).


sundialsvcs 08-13-2021 08:52 AM

Carefully read the Django documentation on modules. Yes, it might be a tpyo!

maschelsea 08-16-2021 12:43 AM

Quote:

Originally Posted by shruggy (Post 6274622)
Could it be a typo somewhere in the script? Like app instead of apps? You probably have something like
Code:

from django.apps import apps

You were right. In my <root>/settings.py it said to import jobs.app.JobListing. I changed it from app to apps and it started up. Thank you for your help!


All times are GMT -5. The time now is 07:58 PM.