It seems a simple problem so I thought it would already be answered, but none of the explanations I found on the internet contained a solution that was valid for me.
So, I just want to be able to import functions from a file that is in the same folder as the file where I want to use them. It was written everywhere that I just had to write import my_file
, but I just get a ImportError: No module named my_file
I tried to add an empty __init__.py
file in the folder but it didn't work. I didn't try other too complicated solutions because there should be a simple one and I feel like I'm just missing something basic yet indispensable.
So, I made a test as simple as possible with just a folder Folder
containing two files, file1.py
and file2.py
.
Here is the content of file1.py
:
import file2
f()
And here is the content of file2.py
:
def f():
print "it works !"
When I execute file1.py
, i get the following error at line 1:
ImportError: No module named file2
(I tried with all possible combinations presence and absence of quotes, parentheses and .py extension, with most of them I get a SyntaxError: invalid syntax
)