PyCharm not recognizing Python files
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.
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:
- (from OSX): PyCharm → Preferences → IDE Settings → File Types
- Select the affected File Type from the list on the top half of this dialog box,
Recognized File Types
(in my case, Text Files) - 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 theRegistered Patterns
list. - Click
Apply
- 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.
- Go to
File > Settings > Editor > File Types > Text
- Under
Registered Patterns
, I found the newmyfilename.py
in the list. - Remove it from the list with the
-
button - 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.
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.
- Go into preferences
- In the project settings click project interpreters and then Configure Interpreters
- Delete the existing Interpreters (using '-' and bottom) and then click OK at the bottom
- 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
- 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.
- Click Ok again, wait a minute or two for rebuilding indexes and viola it works (for me at least)
belteshazzar
Updated on November 12, 2021Comments
-
belteshazzar over 2 years
PyCharm is no longer recognizing Python files. The interpreter path is correctly set.
-
Ryan Currah over 9 yearsFix worked for me PyCharm 3.4.1 for Linux. views.py got accidentally added to the list of TextFiles... Frustrating few days thanks.
-
brooc about 9 yearsI had the same problem but the file name was added to the text file extension
-
user1211030 over 6 yearsAny idea why the file is added to that list of text files in the first place?
-
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 over 6 yearsFor me this was hidden in
Setting | Editor | File Types
. (2017.3.2) -
jpp1 almost 6 yearsDid 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 almost 6 years@user1211030 I had this happen when I used
New > File
instead ofNew > 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 almost 5 yearsThis 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 almost 5 years3. 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
tofoo.py
thinking that I need a file name. 4. I renamed the file tofoo.py
thinking it didn't work or something. 5. Now the file is namedfoo.py
and I have a rule saying thatfoo.py
is a text file. -
kranberry over 3 yearsFYI 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 almost 3 yearsWelcome 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 almost 3 yearsYour 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.