36

I'm trying to use PyCharm IDE but none of my programs compile even simple Hello World. PyCharm gives this error:

Fatal Python error: Py_Initialize: can't initialize sys standard streams
Traceback (most recent call last):
  File "C:\Python34\lib\io.py", line 72, in <module>
AttributeError: 'module' object has no attribute 'ABCMeta'
Process finished with exit code 3

I'm not able to find the solution for it and also referred the link PyDev: Fatal error Python32\lib\io.py, line 60, in <module> but there is no solution there.

Python 3.4 is installed on my Win 7 OS system.

Georgy
  • 9,972
  • 7
  • 57
  • 66
  • 25
    Change your file's name from `io.py` to something else. – Burhan Khalid Oct 26 '14 at 05:36
  • 4
    I solved my issue. Apparently PyCharm is not able to execute a file named `abc.py` because there is an in-built module called abc in Python. Executing `abc.py` via command line works. Check if your file is named `abc.py`, if it is, rename it to something else. – iridescent Oct 26 '14 at 10:27
  • @BurhanKhalid can you explain more about why is that the issue and how to avoid it? I cannot find list of "reserved filenames" or anything similar. – Dusan Vasiljevic Oct 29 '19 at 03:50
  • 3
    I had a similar problem. Earlier I had named my package 'io' – lab bhattacharjee Dec 28 '19 at 13:19

6 Answers6

75

I faced the same problem because I created a file named abc.py, remove that file in your project, your error will disappear.

Marcs
  • 3,600
  • 5
  • 31
  • 42
vinay
  • 751
  • 5
  • 2
  • why the file name abc.py is not supported in pycharm? – HarshitMadhav Mar 16 '18 at 19:27
  • 11
    If you name your file abc.py you're shadowing the [standard library's abc (abstract base class)](https://docs.python.org/3/library/abc.html). When you do that, everything that depends on the built-in abc will get yours instead. Unless you've essentially rewritten the standard library's code, things will break. – Ernst Jun 28 '18 at 09:57
  • Echoing @david-c, changing the name of the module may work, but it should not be necessary. Unchecking a few boxes in "Run/Debug" configurations is a better solution. – Keith Ma Mar 28 '20 at 16:08
  • it worked fine for me.. – Mugeesh Husain Jan 12 '22 at 08:52
16

Yes, as you said in the comment, the problem is in the filename 'abc'. You will be able to run this file within PyCharm, if you uncheck:

  • Add content roots to PYTHONPATH
  • Add sources roots to PYTHONPATH

in the menu "Run/Debug Configurations".

  • This is what worked for me. I suspect it should be the accepted answer. There should be no magic-forbidden module names such as "abc.py". – philologon Jun 25 '18 at 17:38
  • Also worth checking to make sure the 'working directory' option isn't pointing to your file or subpackage. – David C Feb 05 '19 at 22:50
  • In my case it was because the content root was a package installed to my local environment with `pip install -e .`. – user2015762 Jan 07 '22 at 14:36
12

I have the same problem, just change your file's name from io.py to something else, It's work!

janeluck
  • 121
  • 1
  • 4
  • This is just plain odd. I had to rename one of my packages its name was io and when debugging(and only then) would it not work! Afer changing to inout all worked. – MatBos Jul 24 '18 at 20:09
6

Finally found how to solve this problem in PyCharm: never use a name like abc.py or test.py.

Simply use another name, like a.py or my-unique-file-name.py

Deqing
  • 12,998
  • 13
  • 78
  • 120
2

try this: File->Setting->Editor->File Encodings change the Project encoding to UTF-8

張家豪
  • 21
  • 3
0

In my case from .my_file import * caused the error. Changing it to from .my_file import func_1, func_2, func_3 solved it.

mmichal10
  • 170
  • 1
  • 11