Python Forum
ModuleNotFoundError - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: ModuleNotFoundError (/thread-13995.html)



ModuleNotFoundError - saladgg - Nov-10-2018

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?


RE: ModuleNotFoundError - Larz60+ - Nov-10-2018

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-pythonic-__init__py.html


RE: ModuleNotFoundError - saladgg - Nov-11-2018

(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-pythonic-__init__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!