So i just started learning Django recently and i have spent a whole day and a half trying to figure how to fix this issue, here is a little breakdown. So my first Django Project was called "RuffGram:[don’t ask] which i had to delete because i did not set up the virtual environment correctly so a lot of my python commands were not working but some reason I was able to get django up and running still, deleted this file completely out of my computer. Then i created another project the correct way, making the virtual environment first and then installing the virtualenv package , activating the virtual env and reinstalling the django package. Now the error i keep getting is when i try to run [ py manage.py run server or py manage.py migrate], the error i keep getting is [ModuleNotFoundError: No module named ‘RuffGram’], which was my first django project that i deleted off of my computer. I have tried setting the Django Settings Module default to my new project settings, i have tried running the server with [django-admin runserver settings=“PetSocialMedia/settings”] and then i get the error ModuleNotFoundError: No module named ‘PetSocialMedia’] which is the name of my new project and still nothing, i have spent a day and a half and no AI or youtube video has been able to help.
First show your directory structure here for your project.
In the default case, you’ll have a “project directory” that everything else resides in (except for possibly your virtual environment, which can pretty much reside anywhere.
Inside this “project directory” you’ll have your manage.py
file, by default another directory with the same name as your project directory, and one or more directories for apps.
In addition to showing your directory structure, please post the contents of your manage.py
file.
When posting code here, enclose the code between lines of three backtick - ` characters. This means you’ll have a line of ```, then the code, then another line of ```.
here is my directory structure-
─PetSocialMedia
│ manage.py
│
├───BlogPost
├───migrations
│ ├───settings
│ └───templates
│ └───BlogPost
│ │ admin.py
│ │ apps.py
│ │ models.py
│ │ tests.py
│ │ urls.py
│ │ views.py
│ │ __init__.py
│ │
│ ├───migrations
│ │ __init__.py
│ │
│ ├───settings
│ └───templates
│ └───BlogPost
│ base.html
│ home.html
│ login.html
│ register.html
│
└───PetSocialMedia
asgi.py
settings.py
urls.py
wsgi.py
__init__.py
Also here is the code for my manage.py, it is set to the correct Project name but whenever I run a manage.py command it runs using RuffGram which is a project and the delete. here is the code.
#!/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', 'PetSocialMedia.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()
Please post the complete error from the manage.py
command, and the contents of your PetSocialMedia/BlogPost/apps.py file.
Side note: The three backticks must be on lines by themselves. They must not be part of other lines. (I fixed your directory tree display for that, but the spacing on some of the items doesn’t look right.)
(Also, look for any instance of the text “RuffGram” in any file in your project.)
Apologies, i will fix it, here is the complete error code.
Traceback (most recent call last):
File "c:\Users\Titan\OneDrive\Desktop\PEtSocialMedia\new_enviroment\Lib\site-packages\django\core\management\base.py", line 412, in run_from_argv
self.execute(*args, **cmd_options)
File "c:\Users\Titan\OneDrive\Desktop\PEtSocialMedia\new_enviroment\Lib\site-packages\django\core\management\commands\runserver.py", line 74, in execute
super().execute(*args, **options)
File "c:\Users\Titan\OneDrive\Desktop\PEtSocialMedia\new_enviroment\Lib\site-packages\django\core\management\base.py", line 458, in execute
output = self.handle(*args, **options)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "c:\Users\Titan\OneDrive\Desktop\PEtSocialMedia\new_enviroment\Lib\site-packages\django\core\management\commands\runserver.py", line 81, in handle
if not settings.DEBUG and not settings.ALLOWED_HOSTS:
^^^^^^^^^^^^^^
File "c:\Users\Titan\OneDrive\Desktop\PEtSocialMedia\new_enviroment\Lib\site-packages\django\conf\__init__.py", line 89, in __getattr__
self._setup(name)
File "c:\Users\Titan\OneDrive\Desktop\PEtSocialMedia\new_enviroment\Lib\site-packages\django\conf\__init__.py", line 76, in _setup
self._wrapped = Settings(settings_module)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "c:\Users\Titan\OneDrive\Desktop\PEtSocialMedia\new_enviroment\Lib\site-packages\django\conf\__init__.py", line 190, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Titan\AppData\Local\Programs\Python\Python312\Lib\importlib\__init__.py", line 90, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
File "<frozen importlib._bootstrap>", line 1310, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
File "<frozen importlib._bootstrap>", line 1310, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
File "<frozen importlib._bootstrap>", line 1324, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'RuffGram'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Titan\OneDrive\Desktop\PEtSocialMedia\PetSocialMedia\manage.py", line 22, in <module>
main()
File "C:\Users\Titan\OneDrive\Desktop\PEtSocialMedia\PetSocialMedia\manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "c:\Users\Titan\OneDrive\Desktop\PEtSocialMedia\new_enviroment\Lib\site-packages\django\core\management\__init__.py", line 442, in execute_from_command_line
utility.execute()
File "c:\Users\Titan\OneDrive\Desktop\PEtSocialMedia\new_enviroment\Lib\site-packages\django\core\management\__init__.py", line 436, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "c:\Users\Titan\OneDrive\Desktop\PEtSocialMedia\new_enviroment\Lib\site-packages\django\core\management\base.py", line 425, in run_from_argv
connections.close_all()
File "c:\Users\Titan\OneDrive\Desktop\PEtSocialMedia\new_enviroment\Lib\site-packages\django\utils\connection.py", line 84, in close_all
for conn in self.all(initialized_only=True):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "c:\Users\Titan\OneDrive\Desktop\PEtSocialMedia\new_enviroment\Lib\site-packages\django\utils\connection.py", line 76, in all
return [
^
File "c:\Users\Titan\OneDrive\Desktop\PEtSocialMedia\new_enviroment\Lib\site-packages\django\utils\connection.py", line 73, in __iter__
return iter(self.settings)
^^^^^^^^^^^^^
File "c:\Users\Titan\OneDrive\Desktop\PEtSocialMedia\new_enviroment\Lib\site-packages\django\utils\functional.py", line 47, in __get__
res = instance.__dict__[self.name] = self.func(instance)
^^^^^^^^^^^^^^^^^^^
File "c:\Users\Titan\OneDrive\Desktop\PEtSocialMedia\new_enviroment\Lib\site-packages\django\utils\connection.py", line 45, in settings
self._settings = self.configure_settings(self._settings)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "c:\Users\Titan\OneDrive\Desktop\PEtSocialMedia\new_enviroment\Lib\site-packages\django\db\utils.py", line 148, in configure_settings
databases = super().configure_settings(databases)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "c:\Users\Titan\OneDrive\Desktop\PEtSocialMedia\new_enviroment\Lib\site-packages\django\utils\connection.py", line 50, in configure_settings
settings = getattr(django_settings, self.settings_name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "c:\Users\Titan\OneDrive\Desktop\PEtSocialMedia\new_enviroment\Lib\site-packages\django\conf\__init__.py", line 89, in __getattr__
self._setup(name)
File "c:\Users\Titan\OneDrive\Desktop\PEtSocialMedia\new_enviroment\Lib\site-packages\django\conf\__init__.py", line 76, in _setup
self._wrapped = Settings(settings_module)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "c:\Users\Titan\OneDrive\Desktop\PEtSocialMedia\new_enviroment\Lib\site-packages\django\conf\__init__.py", line 190, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Titan\AppData\Local\Programs\Python\Python312\Lib\importlib\__init__.py", line 90, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
File "<frozen importlib._bootstrap>", line 1310, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
File "<frozen importlib._bootstrap>", line 1310, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
File "<frozen importlib._bootstrap>", line 1324, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'RuffGram'
This really does look like you still have a reference to RuffGram
either in your settings or in a file that settings references.
apologies for the late response, I have looked through my settings line of code a couple times there isnt any reference to Ruffgram in the file, but it may perhaps be in the other files that reference the settings like you suggest. I actually went ahead started a different project from scratch again and i am still getting that same exact error with RuffGram again, not sure what else to do.
When you started your new project, did you create everything from scratch - including a new virtual environment? That would be the next step here if you can’t find any reference to RuffGram
anywhere within any file in this project.
yes every time i started a new project i would start the virtual environment from scratch as well, to add on I looked up RuffGram through all the files on my computer and i found a text file called envVars, in there it shows the Django_SETTINGS_MODULE save as RuffGram when i click on it shows me a path that leads into my Visual Studio Codes extension the full path is below:
"C:\Users\Titan\.vscode\extensions\ms-python.python-2023.22.1\pythonFiles\deactivate\powershell\envVars.txt"
This is the only reference i have been able to find
Figured it out, for some reason my python could not access Django == 5;
so i had to use and older version of django.