Nautilus and Nemo use two different icons for python files:

Two different icons for python files

But I want them to show the python icon for all python files.

mimetype gives the same result for both files:

$ mimetype *.py
buy_test.py:         text/x-python
candlestick_test.py: text/x-python

file -i gives different outputs:

$ file -i buy_test.py 
buy_test.py: text/x-python; charset=us-ascii
$ file -i candlestick_test.py 
candlestick_test.py: text/x-objective-c; charset=us-ascii

The output for candlestick_test.py is wrong but this file is shown with the python icon. No idea why.

Somebody here had the same problem: Ubuntu file manager is not showing proper icons

But the answer he got, doesn't work for me:

$ grep -r 'text/x-python' /usr/share/thumbnailers

No output.

I think the main diffenrence between these python files is the shebang:

$ head -n2 buy_test.py 
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
$ head -n2 candlestick_test.py 
# -*- coding: utf-8 -*-

When I use this shebang (python 2) ...

#!/usr/bin/env python

... there is a python icon, too.

How do Nautilus and Nemo choose file icons?


Some additional information:

There is a python icon if I use one of these shebangs:

#!/usr/bin/env python

There is no python icon if I use one of these shebangs:

#!/usr/bin/env python3

So it looks like python3 is a problem.


xdg-mime query filetype FILENAME returns the MIME type matching the shebang:

$ xdg-mime query filetype buy_test.py 

$ xdg-mime query filetype candlestick_test.py 

And when I change candlestick_test.py's file extension to .py3, the python icon disappears and xdg-mime query filetype returns text/x-python3.


I found a new source of information:

$ gio info ~/python/buy_test.py | grep icon
  standard::icon: text-x-python3, text-x-generic
  standard::symbolic-icon: text-x-python3-symbolic, text-x-generic-symbolic, text-x-python3, text-x-generic
$ gio info ~/python/candlestick_test.py | grep icon
  standard::icon: text-x-python, text-x-generic
  standard::symbolic-icon: text-x-python-symbolic, text-x-generic-symbolic, text-x-python, text-x-generic

So I guess, I have to link text-x-python3 files to text-x-python icons somehow.

  • Thanks for editing! I'm not yet allowed to embed images.
    – MaxGyver
    Aug 19, 2018 at 10:05
  • Don't think a shebang matters per se, here as long as python is in the file (or in near top?) it gets the icon. Ex, a empty text file named 1.py = no icon. Add just #python or python to it = icon.
    – doug
    Aug 19, 2018 at 16:33
  • My first example (buy_test.py) does have "python" within its first line but no icon. The other file has no "python" in its first line but there is a python icon. If I use just "#python" instead of "#!/usr/bin/env python3", I can't run my script via ./buy_test.py anymore.
    – MaxGyver
    Aug 19, 2018 at 16:55

2 Answers 2


Finally I could fix it!

As far as I understand, Nemo and Nautilus try to load a file named text-x-python3.svg from /usr/share/icons/[MyTheme]/mimes/[ActualIconSize]/. If there is such a file in ~/.local/share/icons/[MyTheme]/mimes/[ActualIconSize]/ it has a higher priority. But none of these directories existed for my theme: Humanity-Dark.

So Nemo/Nautilus try to find that icon in another theme. In /usr/share/icons/Humanity-Dark/index.theme is defined which theme to try next:

$ grep Inherits /usr/share/icons/Humanity-Dark/index.theme 

Next try is Humanity. There are icons for text-x-python but not for text-x-python3. So I did:

mkdir -p ~/.local/share/icons/Humanity-Dark/mimes/48
cp /usr/share/icons/Humanity/mimes/48/text-x-python.svg ~/.local/share/icons/Humanity-Dark/mimes/48/text-x-python3.svg

Same for icon sizes 16 and 22. Now it looks as expected:

Python icons as expected

Maybe this solution is helpful for someone else.


I had a nearly identical problem in Thunar. I had a slightly different solution. I'm using the elementary Xfce icon theme, so change the commands below as appropriate:

sudo ln -s /usr/share/icons/elementary-xfce/mimes/32/text-x-python.png /usr/share/icons/elementary-xfce/mimes/32/text-x-python3.png
sudo ln -s /usr/share/icons/elementary-xfce/mimes/48/text-x-python.png /usr/share/icons/elementary-xfce/mimes/48/text-x-python3.png
sudo ln -s /usr/share/icons/elementary-xfce/mimes/64/text-x-python.png /usr/share/icons/elementary-xfce/mimes/64/text-x-python3.png
sudo update-icon-caches /usr/share/icons/*

The last command to refresh the icon cache was necessary for me to see the changes in Thunar. After running the commands above I simply refreshed the directory in Thunar and everything was working as expected.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .