python manage.py runserver fails module not found 'projectname'

Hello,
I’ve been struggling for this, and when I say I haven’t found anywhere on the web the solution, I say the truth;
I barely started to get into django, ran django-admin startproject projectname; then cd into projectname, and then run there python manage.py runserver, and it throws module not found ‘projectname’; I saw so-said solutions on forums such as stackoverflow, which said add the projectname in settings.py INSTALLED_APPS; which I do not agree at all, as in the official documentation there was no need to do such thing for the project to launch; but still I did it, I tried, I added ‘projectname’ in the list INSTALLED_APPS in settings.py, still nothing;

project structure
/projectname
------ /projectname
----------- /init.py
----------- /asgi.py
----------- /settings.py
----------- /urls.py
----------- /wsgi.py
------ manage.py

//manage.py

#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys


def main():
    """Run administrative tasks."""
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'gisacri.settings')
    try:
        from django.core.management import execute_from_command_line
    except ImportError as exc:
        raise ImportError(
            "Couldn't import Django. Are you sure it's installed and "
            "available on your PYTHONPATH environment variable? Did you "
            "forget to activate a virtual environment?"
        ) from exc
    execute_from_command_line(sys.argv)


if __name__ == '__main__':
    main()

the files are all from the default, nothing edited yet; brand new projects fail; I tried recreating again and again, still fail;

I’m running on windows 10, python 3.9.4
what is the matter here??? help anyone :dotted_line_face:

I always recommend people start with the Official Django Tutorial or the Django Girls Tutorial.

Follow either of these completely, and exactly, and you should be on your way. If you’re having problems with any of the specific steps in them, feel free to post again here with the specific step you’re trying and the error message(s) you are receiving.

indeed I followed it completely, and exactly, that is what I say in the post, in the official documentation; but I’m getting this modue not found error, whereas it should, as per the official django tutorial, work

Ok, you failed to mention that you were working through the tutorial - runserver is covered in multiple places in the documentation.

When you say you cd projectname, are you saying your current directory is the “outer” projectname directory or the inner one? (You should be in the outer project-level directory named projectname, not the inner one with the various files.)

Also, what version of Django are you using?

I’m in the outer one, and obviously manage.py won’t run if I was in the inner one, unless I created a manage.py, which I didnot;
version is 4.1.3

Another question, are you actually using projectname as the name of the project, or something else? Your manage.py file seems to imply that your project is actually called gisacri.

the projectname is gisacri;

So then are the directories named gisacri or projectname?

the directories are named after the name I put in startproject “name”; they are named gisacri here

so inside the outer gisacri it is I run the manage.py runserver; not in the inner gisacri, which won’t have a manage.py file;
and the django version is 4.1.3

Unfortunately, I can’t recreate the behavior you’re reporting with a Windows 10 system running Python 3.9.4 and Django 4.1.3. I can’t think of any reason right off-hand what might cause this specific behavior other than something either being wrong with the environment at the time you’re running runserver or something really odd regarding file permissions and access.

Are these all local directories on your windows system or are any shares involved?

these are all local directories;
even I am lost;
but in case it can help; I use the python embedded version, the zip one; but still I do not think that’s a problem

and also, I use visual studio code

Are you trying to run this from within VSCode? If so, it might be worth trying to run it directly from a Command Prompt window. That would at least help identify if it is a VSCode-related issue.

yes, I tried also from cmdline, still the same output;
but actually I think this is a matter of modue stuff; I ran manage.py without args to see how it’d output, and saw there was a note in the bottom:
“Note that only Django core commands are listed as settings are not properly configured (error: No module named ‘gisacri’).”
so actually it is the gisacri.setings notation in the manage.py that causes the problem; obviously gisacri is not a module;
and I saw on the docs about settings.py
“settings file is just a Python module”
“Note that the settings module should be on the Python import search path.”

why aren’t this thing explained on the beginner tutorials? shouldn’t these actually be mentioned there? if I’m correct so the project must be a python module, so it should be listed also when we do pip list; but the beginner tutorial says nothing about this, how are beginners then supposed to know?

This statement is incorrect. Assuming your inner directory is named ‘gisacri’ as you’ve mentioned above, that makes it a module when the containing directory is your current directory. (This isn’t Django specific, see 6. Modules — Python 3.11.0 documentation)

You are not correct. There is no need for it to be listed in pip list. (You don’t see any of Python’s stdlib in pip either.) Again, this isn’t something specific or peculiar to Django, this is standard Python.

All I can say so far is that assuming your directory listing in the first post is accurate (except for the directory names being gisacri), everything you’ve posted here looks correct and should work. Whatever is causing this issue is not due to your project - at least what you’ve shown here so far - there’s something else wrong.

What directory is your outermost gisacri directory in?

Are you using a virtual environment, or are you running this using system-level installed modules?

Did you make any changes to your settings.py file, or is it still as it was when it was created by startproject?

Here’s a sample I that I just tried:

Notice that it’s referencing mytest.settings in the third line from the end.

oh I see; so it should work; but still it doesn’t;

it is inside a directory in D:; I thought perhaps because the full path contains spaces that it is unfindable, so I tried creating the project inside C:\users\0010\desktop, still the same

I’m using system-level installed modules, no virtual environments

no, as I already said I just do startproject, then cd into the folder and run manage.py runserver, and it just fails

so if I’m correct sys.path should output the current directory??
in my case I run a python shell inside the outer gisacri and run sys.path and the directory is not listed there

EDIT: ahh! this is a matter of python distribution, the embeddable package; a matter of ._pth file stuff; bref I get it; so indeed it does work with a normal python installation; sorry for the troublemaking :sweat_smile: :grin:

Hey, I’ve been running into the same problem. Can you further explain the solution you came up with? I can’t even start my tutorial project

If you’re having a problem with which you are requesting assistance, I suggest you open a new topic here with all the relevant information.