darlinghq / darling

Darwin/macOS emulation layer for Linux
http://www.darlinghq.org
GNU General Public License v3.0
11.55k stars 446 forks source link

xattr fails with Python 'ImportError: No module named _xattr' #819

Open r-wilbur opened 4 years ago

r-wilbur commented 4 years ago

Darling [\~]$ xattr Traceback (most recent call last): File "/usr/bin/xattr-2.7", line 11, in load_entry_point('xattr==0.6.4', 'console_scripts', 'xattr')() File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/init.py", line 565, in load_entry_point return get_distribution(dist).load_entry_point(group, name) File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/init.py", line 2697, in load_entry_point return ep.load() File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/init.py", line 2370, in load return self.resolve() File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/init.py", line 2376, in resolve module = import(self.module_name, fromlist=['name'], level=0) File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/xattr/init.py", line 15, in import _xattr ImportError: No module named _xattr

r-wilbur commented 4 years ago

Do we need to modify the 'sys.path' before we try to 'import _xattr'? Does 'lib_xattr__py27.dylib' need to have execute permissions? Here is what darling sees in the installed xattr module:

Darling[~]$ ls -l /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/xattr/   
total 144
-rw-r--r--  1 awilbur  awilbur   5705 May 17 20:32 __init__.py
-rw-r--r--  1 awilbur  awilbur  10318 May 22 05:48 __init__.pyc
-rw-r--r--  1 awilbur  awilbur    489 May 17 20:32 constants.py
-rw-r--r--  1 awilbur  awilbur    461 May 22 05:48 constants.pyc
-rw-r--r--  1 awilbur  awilbur  34684 May 28 22:22 lib_xattr__py27.dylib
-rw-r--r--  1 awilbur  awilbur   6473 May 17 20:32 tool.py
Darling [~]$ 
HinTak commented 4 years ago

I suspect you need to unset some of your python environment variables!

r-wilbur commented 4 years ago

@HinTak: Should I unset python environment variables in Linux or Darling? I have not specifically set any python environment variables in either operating system.

I run Darling by invoking

awilbur@eureka:~$ darling shell
Darling [/Volumes/SystemRoot/home/awilbur]$ xattr
[same traceback as above]
HinTak commented 4 years ago

@r-wilbur argh, I managed to reproduce your problem too! It looks like the xattr package under darling or Mac os x itself is a bit broken (not surprising as there is not much use of it on mac's file system - real mac users play with the resources fork with different tools). That said, I have a work around: you can copy lib_xattr__py27.dylib to where _ctypes.so is, and called it _xattr.so. xattr then works!

This is inspired by my recent work with ctypes - I know ctypes works under darling, and there are similarity between it and xattr (both provides a bridge to native c libraries).

I don't know where the problem is. Probably something to do with the dynamic loader, and could be darling specific, or generic also to genuine mac os x. The renaming , after copying, may not be required (do it under darling shell so that darling is immediately aware of the copy - doing it outside darling would be slightly inadvisable) - I'd be interested to know if the original name, or just removing the "__py27" part, etc works too. Hopefully the workaround points towards a fix.

HinTak commented 4 years ago

_ctypes.so is located a few directory above, under ../2.7/lib/python2.7/lib-dynload/

r-wilbur commented 4 years ago

@HinTak Thanks for the wonderful hint! I tried copying lib_xattr__py27.dylib to lib_xattr.dylib in the current install directory and it didn't work. But copying it to _xattr.so in the same directory did! Turns out I got the same results in each directory. Paths tried:

/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/xattr # install dir
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/
Name Tried Success
lib_xattr__py27.dylib not found
lib_xattr.dylib not found
lib_xattr.so not found
_xattr.so found

So the next thing to do would be to modify the build to create _xattr.so instead of lib_xattr__py27.dylib, I guess.