Invalid python3 relative import: ImportError: Unable to import name 'gmail'

I understand that relative imports should be explicit in python 3, but I cannot figure it out.

I have one directory called work and files main.py and gmail.py

In main.py I used "import gmail" in python 2

I just used 2to3 and this line was changed to "from. Import gmail"

user@ubuntu:~/work$ python main.py 
Traceback (most recent call last):
  File "main.py", line 7, in <module>
    from . import gmail
ImportError: cannot import name 'gmail'

      

What am I doing wrong?

By the way, when I do "python gmail.py" it works great.

$ cat main.py 
from . import gmail

$ cat gmail.py 
print('test')

      

====================================== Ok, I found this works $ cat main. py import gmail

So why did 2to3 change this to something that doesn't work? And why do people say they use "from. Import gmail" when "import gmail" is running?

+3


source to share





All Articles