pycharm association to .py files requires shebang
I don't know when this started, or if I've somehow completely screwed up my PyCharm configuration, but I can't get pycharm to associate .py files as Python in Pycharm (ie for the purposes of syntax highlighting) unless I have a python shebang (`#!/usr/bin/env python3`) in the file, or I explicitly tell PyCharm for each and every .py file “Override file type” → Python.
I don't have shebang lines in python library/module code, because they're not meant to be run as standalone scripts.
This is made worse because I use syncthing to keep projects sync'd across computers, but I intentionally do not sync the .idea directories because paths are not always exactly the same (ie Mac vs Linux). So the file type association doesn't sync with the project. The filetype association shouldn't need to sync, and I shouldn't have to do manual associations because PyCharm should already know that “.py” files are python?
Figured I'd ask here before I log this as a bug in case it's something stupid I did to PyCharm.
Please sign in to leave a comment.
I thought I solved my own problem by finding that Settings > Editor > File Types only had “*.pyw” listed as a recognized type. I tried to add “*.py” to the list and PyCharm says “This wildcard is already registered by ‘File type auto-detected by file content’ filetype"
And indeed, there is a type called “File type auto-detected” and it has “*.py” which suggests that this is not working properly?
I don't need or care about opening files in PyCharm, I just want PyCharm to recognize the extension “.py” means this is a python file and it should treat it as such for the purposes of syntax highlighting, code inspection, etc.
Hi Richard Hornsby
This happens if you have mapped *.py in File type auto-detected by file content section
You can simply click reassign in the popup box you have attached or simply remove it from here so then you will not be warned again when trying to add *.py in Python section.
Hope this helps
Kind regards,
Thanks for the suggestion. It makes sense that this would be the solution, but I assumed that since I didn't set
*.pyto “auto-detected by file content” then that's the way PyCharm is supposed to be configured.I reassigned the extension, which should fix it. Thanks again.