Souvik Ray
Souvik Ray

Reputation: 3018

Cannot import a file in another file

I have a file calc.py where I have methods for basic calculations.Now I crate another file (in the same directory) called test_calc.py for unittesting the methods in calc.py file.But in the test_calc.py file,when I type import calc, it says 'no such module'.If I am in the same directory,why can't I import calc?

Here is a screen shot of my project structure enter image description here

This is what I get when I try to import calc into the test_calc.py file enter image description here

So what is going wrong?

Upvotes: 2

Views: 967

Answers (1)

VonC
VonC

Reputation: 1324827

Try at least, as recommended here

 from . import calc

Python 3 doesn't allow implicit relative imports.

Upvotes: 2

Related Questions