PyCharm not recognizing Python files

PyCharm is no longer recognizing Python files. The interpreter path is correctly set.

Screen shot


Please check File | Settings (Preferences on macOS) | Editor | File Types, ensure that file name or extension is not listed in Text files.

To fix the problem remove it from the Text files and double check that .py extension is associated with Python files.

Text


I had a similar problem where certain .py files were showing up as regular text files after completion, thus rendering the code without syntax coloring, tab completion features, etc. Through using this post as a starting point for debugging the issue, I found the following:

  1. (from OSX): PyCharm → Preferences → IDE Settings → File Types
  2. Select the affected File Type from the list on the top half of this dialog box, Recognized File Types (in my case, Text Files)
  3. Listed in the second half of the dialog box, Registered Patterns were the names of the files that I was having naming/syntax issues with. I clicked on each of those and then clicked on the - for each in turn to remove them from the Registered Patterns list.
  4. Click Apply
  5. Sigh of relief when the syntax highlighting returns and the icon changes back to that of a python file.

I accidently made a text file myfilename, renamed it to the myfilename.py version but it stayed with text file formatting even after the extension change.

Here's how I fixed it for For PyCharm 2017.2 for Windows.

  1. Go to File > Settings > Editor > File Types > Text
  2. Under Registered Patterns, I found the new myfilename.py in the list.
  3. Remove it from the list with the - button
  4. Click Ok

I had a similar problem and none of the answers already submitted helped to resolve it.

I eventually discovered that my affected filename was listed in the Auto-detect file type by content section in Preferences->Editor->File Types. Removing the filename from there and apply the changes resolved my issue immediately.

PyCharm File types preferences window