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?

  • xattr is part of OSX and does use python but all the correct bits should be there - have you installed or deleted any python - also which OS verso are you on?
    – mmmmmm
    Mar 29 '14 at 1:36
  • Does ls /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/xattr find anything? That's where the xattr module should be (at least in Mavericks). It should contain _xattr.so and several .py and .pyc files. Mar 29 '14 at 1:58
  • @Mark: That will do as an answer. The core of the question is whether it's a Python package, which I gather it is. (Simply installing it fixes the issue.)
    – orome
    Mar 29 '14 at 13:37
  • @raxacoricofallapatorius How did you install it - it should not be needed - I would reinstall the OS
    – mmmmmm
    Mar 29 '14 at 14:58
  • @Mark: Don't worry about it. I has to do with my Python installation, which is fine. The question is simply whether it has a Python dependency.
    – orome
    Mar 29 '14 at 15:04

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.


Was your /Library/Python/2.7 directory deleted by any chance? Some scripts look for /Library/Python/2.7/site-packages/Extras.pth.

On my Mac, this file contains a couple of lines:


xattr itself is in the first directory above. I faced the same problem today and realized I'd inadvertently deleted /Library/Python/2.7 earlier today thinking it was something else. Xattr went nuts, restoring this directory fixed it.

  • This might well be correct but is not an answer and has been suggested in the comments. Th op says that they had messed around with their python setup and knows all this
    – mmmmmm
    May 3 '20 at 12:36
  • Explaining how the directory can be restored would make this more helpful for others with the same issue.
    – nohillside
    May 3 '20 at 12:52

You must log in to answer this question.

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