Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ModuleNotFoundError
#1
I got two .py files in the same folder. (post.py and user.py) I'm importing user model to post.py using
from user import User
When I run the code I get an error: ModuleNotFoundError: No module named 'user' What am I doing wrong?
Reply
#2
hard to say without seeing all code involved.
Is the code that is doing the importing in the same directory as the imported code?
do you have an __init__.py file (properly set up)? http://mikegrouchy.com/blog/2012/05/be-p...t__py.html
Reply
#3
(Nov-10-2018, 10:00 AM)Larz60+ Wrote: hard to say without seeing all code involved.
Is the code that is doing the importing in the same directory as the imported code?
do you have an __init__.py file (properly set up)? http://mikegrouchy.com/blog/2012/05/be-p...t__py.html

I had to to include the parent folder as part of my import although the two files are in the same folder;
from blog.posts import Post

The reason relates to __init__.py as explained in the link you included.

Thanks!
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020