ModuleNotFoundError: No module named 'django_project.users' - python

** New user to SOF, sorry for poor post and thank you in advance for any help**
As the title says. I have been through multiple threads of StackOverflow with similar questions and none of them have given me a working solution.
My directories
The problem doesn't start until I add line18 into urls.py
and the error:
"ModuleNotFoundError: No module named django_project.users" is displayed.
I have tried different variations of importing the module and all seem to fail.
Traceback
I was following this tutorial:
https://www.youtube.com/watch?v=q4jPR-M0TAQ&t=753s
it wasn't until 14:00 where I was getting errors the author of the video was not. I have been following his tutorial from the beginning and have not run into any errors until now. I have been trying to find a solution for about 4 days now. Any help would be greatly appreciated.
I have pushed the most recent code to github and made the repository temporarily public for anyone who wants to replicate this problem:
https://github.com/ChristopherMillones/PyTest
EDIT: settings.py -> INSTALLED_APPS

django_project is your project root directory.
The apps inside are django_project, blog and users.
If you added those to your settings.py you have to import "stuff" from it like
from users.models import MyModel
In your project itself (django_project/django_project/*) you don't have a module users, that's why the error is thrown.

Related

Python Importing package at same level but different directory

python version:3.9.6
I cannot seem to get this to work I know there are a million posts that are the same as this but the solutions never seem to work for me. I've run into this before and always end up just restructuring the folders to include all files in one path which is obviously not ideal. So here I am once again asking you guys for help.
My folder structure is as follows
|project
|my_service
-my_service.py
|tests
- tests.py
I'm trying to get the function get_num_back from my_service.py and import it into tests.py.
I've tried relative imports from ..my_service.my_service import get_num_back this doesn't work because from what I've read I cannot hit the root folder.
I've then tried absolute import from my_service.my_service import get_num_back which is the answer I see works for everyone else but it doesn't seem to work for me. I've then tried from project import my_service as well as from project.my_service import my_service. as far as I understand with my python version I do not need __init__.py but I've also tried it with that as well.
the error
ModuleNotFoundError: No module named 'project'
Please settle this for me once and for all!
Always run py.test from your project directory.
Because from that directory it can actually find my_service.
For more information, read up on relative imports in the language reference documentation.

Python using Django Framework and Postgres Problems Connecting to Heroku Missing Modules

I am having issues with an older project written with Django, now trying to push it to Heroku with issues. This was set up years ago with the same files by someone else in well under an hour. When I did it all day today, I originally got an error when launching and when running the logs I get:
bash: heroku: command not found
I hired 3 guys to help me that were "well-versed" in these areas. The first person knew quite a bit but came short on pip (pip freeze) and stated that the requirements.txt file was missing the required modules and he couldn't find which ones to include. So I set up a project on a freelance site specifically for someone to help me find modules and fix what's missing. I found a high rated vet with a great reputation specifically in Py/Django/Heroku who said he could help. I shared the exact same git repo I had and within 15 minutes he fixed the problem and shared with me on his localhost. In hindsight I am wondering if he just so happened to have all the modules installed already, being a fulltime Django developer for 6 years? Once I told him how important this is (I am in interview process for an amazing job that wanted to see a postgreSQL example project from my past) he quadrupled the price and held the files hostage.
I hired another Heroku/Django experienced freelancer and showed them everything in advance. He said he could definitely do it but then ran into issues he said with the profile requirements.txt again and my manage.py file which contains:
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "vote.settings")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
He then just blocked me and ghosted. I checked the postgres in heroku and it seems fine, the problem I believe is with finding the modules used if I'm not mistaken? The thing is all guys had the same files/repo and I know at least two got it working with current repo!?
Thanks guys!

Python 3.x import class module not found error

Trying to import a class into my Python code from another .py file I've written and included in the same sub-directory, however I'm receiving the error:
ModuleNotFoundError: No module named 'main.S_DES_Functions'; 'main' is not a package
Please find below images of the layout of my Python project.
I'm hoping this is just a really silly mistake I'm making, so if anyone can please advise what I'm doing wrong that'd be great :)
Thanks for the suggestions, I tried them however was still receiving the same error. But I managed to find a work around, similar to what is listed in this other Stack Overflow question - Unresolved reference issue in PyCharm
I basically made a new directory for my classes and set it as the directory as a "Source" for the project, which then allowed me to import it and use the classes without any issues.

Python ImportError (Cannot import name Variables)

I have done some research on this question and nothing seems to fix it, I suspect I may be accidentally circularly importing somewhere, but this one has stumped me.
This package is a Python IRC Service framework. The issue occurs when dynamically loading a module (via imp.load_source()), and the new module tries to import something from the src folder (Variables.py). It fails with "Cannot import name Variables", yet, it imports another module from the same directory without complaint.
Here is the specific error:
**ERROR: ModLoad(): Unable to load module
/home/sam/workspace/Affinity/bin/../modules/ircd_affinity.py:
cannot import name Variables
**
This is the full file for modules/ircd_affinity.py: ircd_affinity.py, and src/Variables.py: Variables.py
If it helps. browse the entire repository... this (https://github.com/miniCruzer/Affinity/blob/master/src/Affinity.py) module (starting at line 123) loads modules.
I would appreciate if all responses were kept relevant to the specific issue at hand. Yes, it may be tempting to suggest other things I'm doing wrong or otherwise throughout the entire package - I am welcome to suggestions: please e-mail them to me.
Show the full traceback. Look through it for evidence of (attempted) circular import.
Run Python with the -v option ... what does that tell you?
Look at the contents of sys.path and sys.modules just before the error happens.
"**ERROR: ModLoad(): Unable to ..." doesn't look line a Python-raised error. Is that in your code? If so, dig deeper; why is it raised?

Djangobb problem

I've installed Djangobb app on my server (Debian, mod_python) by cloning original source. The only things I've changed is database options in settings.py. All needed components are installed - syncdb query was executed right.
But, when I'm trying to enter on my forum, it returns me error:
ImproperlyConfigured: Error importing middleware django_authopenid.middleware: "No module named djangobb_forum.subscription"
I've checked - djangobb_forum/subscription.py exist, so I don't know what can be wrong.
Maybe someone had problems like that and know how to fix it?
Sorry for my english.
There are two obvious reasons to why this might happen:
djangobb_forum is not on your Python path
There is no __init__.py in the djangobb_forum folder
If the code says from djangobb_forum import ... then you need to have the parent folder of djangobb_forum on your Python path.

Categories

Resources