When I attempt to execute xattr in Terminal, I get

Traceback (most recent call last):
  File "/usr/bin/xattr-2.7", line 33, in <module>
    import xattr
ImportError: No module named xattr

What's going on here? I thought xattr was part of Darwin. Is xattr written in Python? Does it require a Python package to be installed on my system?


The file that is executed when you run the command xattr is /usr/bin/xattr which is a python script that works out what version of python you have and then executes /usr/bin/xattr-2.7 for python 2.7. This script is also python and includes a import xattr to import the python module xattr from the Apple installed python libraries


If you have a version of Python installed with Homebrew, try unlinking it.

brew unlink python

/usr/local/bin/xattr uses the version of Python 3 suggested to it by env. Brew overrides this, but does not include the xattr library, causing this issue.