Python cannot import, unknown location
14,963
It's because parser is a library in python. Use another name for parser file.
Comments
-
LF00 almost 2 years
I've three file in pycharm project like,
project ├── main.py ├── parser.py └── test.py
Both parser.py and test.py have the same code.
def test(): print('test')
But I can only execute main.py with below and it outputs
test
from test import test test()
While when I execute main.py with below,
from parser import test test()
it output's
Traceback (most recent call last): File "C:/Users/lf/Desktop/jye_parser/main.py", line 1, in <module> from parser import test ImportError: cannot import name 'test' from 'parser' (unknown location) Process finished with exit code 1
Here is the project architecture. I can use
Ctrl
+Left Click
to jump to thetest
function in main.py in both case.