Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can a Python script file not be named abc.py?

Tags:

python

pycharm

One day when messing with Python in PyCharm, I encountered a quite silly problem. Namely, when I try to run a simple script in a file named abc.py, I receive an error. I tried to run the same file directly from the terminal and it looks fine.

abc.py

print("Hello world")

Output:

/Users/.../venv/bin/python /Users/.../abc.py
Fatal Python error: init_sys_streams: can't initialize sys standard streams
Traceback (most recent call last):
  File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/io.py", line 52, in <module>
  File "/Users/.../abc.py", line 1, in <module>
RuntimeError: lost sys.stdout

Process finished with exit code 134 (interrupted by signal 6: SIGABRT)

Just out of curiosity, what is the matter here?

EDIT: Why does it happen only when running from PyCharm, and not when from the terminal?

like image 362
dominikbrandon Avatar asked May 25 '20 13:05

dominikbrandon


2 Answers

abc is standard module of python. Here => https://docs.python.org/3/library/abc.html

It should works if you rename your own module abc.py in something else like abcd.py

like image 164
Albert Nguyen Avatar answered Sep 27 '22 22:09

Albert Nguyen


You get an error because python is confused.

You see, there is a built in module in python, that is also called abc(short for 'Abstract Base Classes')!

I suggest you name your file something else, or the other crazy way,

delete the module (just kidding, don't do that!).

like image 34
Ann Zen Avatar answered Sep 27 '22 23:09

Ann Zen