72

I have several django projects and several different files with name utils.py, however pycharm treats them as simple .txt files with no syntax highlighting or any other kind of parsing, how can I fix this?

6 Answers 6

205

Please see File | Settings (Preferences on Mac) | Editor | File Types.

Look for your file name mapped to the Text type or to the Auto-detect file type by content type.

Remove the incorrect mapping and it will fix the issue.

If you still can't find the wrong mapping in the IDE settings, locate the options/filetypes.xml file in the Configuration directory. Close the IDE and either edit this file to remove the incorrect mapping or delete this file to reset all the file types to the defaults.

text files

Sign up to request clarification or add additional context in comments.

9 Comments

the pattern there is CVS;SCCS;RCS;rcs;.DS_Store;.svn;.pyc;.pyo;*.pyc;*.pyo;.git;*.hprof;_svn;.hg;*.lib;*~;__pycache__;.bundle;*.rbc;*$py.class; however utils.py was registered under Text file pattern , removed it.
This is generalizable to other file types getting associated with the wrong extension as well. I had the same problem with one of my .js files getting associated with the plain text file type and this solution fixed my problem.
Ran into this accident today. Thought the filename extension would normally pickup the "Python Type" from the file-association choices, but I must of accidentally type the filename in the type Textfield.
PHPStorm also has this issue - adding this here to hopefully help future googlers.
Per @Nicolas's soon-to-be-deleted comment-as-answer: "In Pycharm 4.5, the File Type menu is in Pycharm | Preferences | Editor"
|
3

As CrazyCoder answered, my file also landed in an unintended association. In my case it was "Auto-detect file type by content". You can just try to add your file to the desired file type (e.g. Python) and PyCharm will automatically try to move the association.

1 Comment

How would the OP do this within PyCharm?
2

FYI, a quick action to reassociate a file's type will be available in the context menu of the Project tool window in IntelliJ IDEA 2021.2 (EAPs should be available publicly around May 2021).

Comments

0

In my case I had to right click the file in question (a django migration) and select Mark as Python. I probably clicked Mark as Plain Text before by mistake.

Comments

0

I actually solved this by going to the Project section , and then clicking Override File Type by right clicking on the specific file. Then I selected the type of the file from the list of available file types.

That worked

Comments

0

For me, the file somehow forgot its type. This can be overridden by

Right click the file name --> Override File Type --> Select file type.

enter image description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.