I'm using Python 3. I have two Python files in the same directory: first.py and second.py. In the beginning of first.py, I use:
from second import *
However, it returns the following error message:
ModuleNotFoundError: No module named 'second'
How should I import it in first.py?
Update: To clarify my specific use-case, I am trying to split my settings.py in Django. I have a main settings.py file and another one that only includes the confidential information. I followed this following documentation that uses the following line in settings.py:
from settings_local import *
Note that settings_local.py is in the same directory. However, it returns the following error message:
ModuleNotFoundError: No module named 'settings_local'
I know the document says "Some of the examples listed below need to be modified for compatibility with Django 1.4 and later." but I do not know how to use it in Python 3.
I just found the solution:
from .settings_local import *
instead of:
from settings_local import *
I found the solution in this thread.
You can use the following code snippet:
from .settings_local import *
This is relative import. More Info here and here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With