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
import python-3.x module


source to share


No one has answered this question yet

See similar questions:

563
Relative imports in Python 3

or similar:

563
Relative imports in Python 3
516
Relative imports per billion
34
How do I import a Python module from a sibling folder?
7
ImportError: No module named utils
3
Can't import quandl in Python 3
0
Python3 relative imports
0
Why doesn't relative imports work in Python?
0
python3.6 ImportError: Unable to import name 'reduce'
0
python docx package error, ImportError: Unable to import name 'Document'
0
Importing classes into python returns cannot import name error



All Articles
Loading...
X
Show
Funny
Dev
Pics