Some people may have wondered, "Why?", But the standard Python library is test. Since there is a package called, an error will occur if test.py or the module imported by test.py uses this package. It's best not to create a script named test.py.
The log below is what I actually tried.
$ echo from test import support >test.py
$ python test.py
Traceback (most recent call last):
File "test.py", line 1, in <module>
from test import support
File "/tmp/tmp.TWTFmPjXqY/test.py", line 1, in <module>
from test import support
ImportError: cannot import name support
$ mv test.py test_.py
$ python test_.py
$
When I run from test import support
in test.py, I get an ImportError, but I can see that if I rename it to test_.py and then run it, no error occurs.
As mentioned above, I was careful because I was caught before, but I accidentally forgot and got caught again, so I wrote the tips with my own caution.
Recommended Posts