PyCharm not recognizing Python files

Viewed 63524

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

Screen shot

16 Answers

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

The most common issue is that you have .py in your txt file types

The other one that happens every now and again, is that you have associated the actual file name to the txt file type

Solution remains the same

navigate to file->settings->file types->text files and look for .py or the "file name" that is being formatted as text

I faced a similar issue on PyCharm 2021.1. As mentioned in the other solutions, the .py file that was being rendered as a text file was not present in the following menu:

File | Settings | Editor | File Types | Recognized File Types | Text | File name patterns

The following worked for me instead:

Select the file in the editor | File | File properties | Associate with File Type...

File type association

What worked for me was to, right-click on the file, then select "Override File Type".

file_override

From the drop down list, select the language you want.

chose_language

(Can not show images as my rep is low, but they are clickable.)

To revive an old conversation here, none of the above answers worked for the newer version of PyCharm due to updates. Upon creating new .py files they were being detected as .txt files and thus not able to run the files, as many others experienced above. I did not get any errors, there was just not any ability to run the file even though it had a .py extension because it was not being detected as a Python file.

PyCharm Version: 2020.1.4 Build: 201.8743.11

Here's what works instead now:

File > Manage IDE Settings > Restore Default Settings

The only problem with this is if you've added a lot of custom settings you'll have to go back in and add them again.

I had a text file that was not recognized by Pycharm as .py after I changed its ending on Windows. The solution was to right click on it in the Project menu (the one on the left that details all files in the project). One of the options was Override File Type. Changing that to Python was successful.

There is a section called "File type auto-detected by file content" under Editor->File Types->Recognized File Types, my file was listed, after removing from there, it got formatted to python

I had the same situation here. Ubuntu 18 - PyCharm2022.1.1 (Community Edition).

Solved as mention above with the right click above the file type.

  1. Find the the file to change in the Project tree (Alt + 1).
  2. Then, click in override file type and choose the extension you need.
  3. Select apply and it is done.

Note: Remember to write the correct extension for Python which is .py in most cases. You can check the extension types in File, Settings, Editor, Code Style, File Types.

I hope it help, regards.

I had a similar situation but the file was not under "Text" in Settings -> Editor -> File Types, it was under "Auto-detect based on file content". Once I deleted it from there, things worked fine.

right click on urls.py -> Override File Type -> Python

Related