PyCharm not recognizing Python files

58,784

Solution 1

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

Solution 2

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.

Solution 3

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

Solution 4

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

Solution 5

Got it to work finally!

I had this same problem. I tried removing the pycharm caches in the ~/Library folders to no avail. Kept saying in the log that "Some skeletons failed to generate..."

So, here is what worked.

  1. Go into preferences
  2. In the project settings click project interpreters and then Configure Interpreters
  3. Delete the existing Interpreters (using '-' and bottom) and then click OK at the bottom
  4. If you have a project loaded it will say "You have no interpreter, configure one now. You can click that or go back into preferences->Project Interpreter->Configure interpreters
  5. Click the + to add a new interpreter. If you are using the os x built-in python, you can select the version you want from the list.
  6. Click Ok again, wait a minute or two for rebuilding indexes and viola it works (for me at least)
Share:
58,784
belteshazzar
Author by

belteshazzar

Updated on November 12, 2021

Comments

  • belteshazzar
    belteshazzar over 2 years

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

    Screen shot

  • Ryan Currah
    Ryan Currah over 9 years
    Fix worked for me PyCharm 3.4.1 for Linux. views.py got accidentally added to the list of TextFiles... Frustrating few days thanks.
  • brooc
    brooc about 9 years
    I had the same problem but the file name was added to the text file extension
  • user1211030
    user1211030 over 6 years
    Any idea why the file is added to that list of text files in the first place?
  • CrazyCoder
    CrazyCoder over 6 years
    @user1211030 probably because of the misclick in the context menu, there is an option to open file as text.
  • Bram Vanroy
    Bram Vanroy over 6 years
    For me this was hidden in Setting | Editor | File Types. (2017.3.2)
  • jpp1
    jpp1 almost 6 years
    Did the same, had the same problem, but file extension .py is not in the "Text" list and PyCharm still does not recognize it, even after a restart (version 2018.2)
  • stevepastelan
    stevepastelan almost 6 years
    @user1211030 I had this happen when I used New > File instead of New > Python File. It created an text file with no extension. When I manually added a .py extension to the filename, PyCharm automatically created a rule to treat that filename as a text file.
  • T Tse
    T Tse almost 5 years
    This might seem to be a really rare case, but it happened for me just now and your answer helped. I ended up in this state through "normal behavior" through the following steps: 1. I right-click on a folder on the file tree and selected "new file" instead of "new python file". 2. I assumed that the .py would be added so I typed the name of my python file (suppose it's foo) and hit enter.
  • T Tse
    T Tse almost 5 years
    3. A dialog box popped up prompting me to associate the file with a file type, and when I'm just simply adding a file I glossed over the text and just changed the input from foo to foo.py thinking that I need a file name. 4. I renamed the file to foo.py thinking it didn't work or something. 5. Now the file is named foo.py and I have a rule saying that foo.py is a text file.
  • kranberry
    kranberry over 3 years
    FYI I found my file in the "Auto-detect file type by contents" file type; which, despite the name, was somehow preventing the file from being recognized detected as a Python file.
  • Alex Waygood
    Alex Waygood almost 3 years
    Welcome to Stack Overflow! Your answer might be more helpful to others if you explained how/why it works, and/or why this solution is better than the existing answers that have already been here for a while :)
  • Admin
    Admin almost 3 years
    Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.