9

I work in Ubuntu16.04 x64 use python3.5 IDEA but I got a strange question as in picture,I try rename connect,but it can't work.

How should I solve this problem? Please tell me if you known,thinks.

enter image description here

Shakeer Mirza
  • 5,054
  • 2
  • 18
  • 41
Leal Li
  • 247
  • 1
  • 2
  • 10

3 Answers3

3

Try the following:

from .tpymysql import connect
Isma
  • 14,604
  • 5
  • 37
  • 51
close2zero
  • 85
  • 8
  • I think this is the right answer. And see [Changes in import statement python3](https://stackoverflow.com/questions/12172791/changes-in-import-statement-python3) for background – nealmcb Nov 05 '18 at 04:44
0

I think there is something likeclass Connect() in your connect.py.

If the script to be executed is under the same path to connect.py

from connect import Connect

Else

from tpymysql.connect import Connect

The Pythonic way is making everything clear and specific. So when you want to import something, import what's inside other than the file itself.

daiyanze
  • 103
  • 7
0

Python3 usually throws this ImportError for relative imports. Seems relative imports are not necessary.

Try:

import tpymysql

tfad334
  • 558
  • 6
  • 14