added path for local homebrew installation
I wrote this little fix in order to access libmagic in mac even if it's installed with brew on user's home folder.
If you set this in your environment:
export DYLD_LIBRARY_PATH=$HOME/.brew/lib
does that solve the problem? I'm hoping to move away from lots of platform-specific lib search paths, and for this one in particular I'd have to look more closely to see if it's a security issue.
Hi Adam,
Thank you for the response. Unfortunately, it doesn’t work.
I’ve configured the export variable, as you wrote, but the error is still present: File "/Users/manuele.ventoruzzo/miniforge3/envs/geocallai/lib/python3.9/site-packages/magic/loader.py", line 49, in load_lib raise ImportError('failed to find libmagic. Check your installation') ImportError: failed to find libmagic. Check your installation
I used the last version of python-magic available on pip: 0.4.27
Kind regards, Manuele.
Hi @ahupp,
Did you read my reply? How can we do it? With the environment variable, as you wrote, does not work. Could you approve the change that I proposed?
Thank you, Manuele.
I'm having this issue as well. A fix would be great :)
@manvento What are the contents of ~/.brew/lib? If libmagic does not appear there, does it appear after running brew link libmagic?
In the next breaking change I'd like to remove the homebrew-specific bits in magic/loader entirely, since the glob for ../Cellar/* is better handled with using brew link and standard paths. This just isn't the right layer to solve the problem. Also, AFAICT, ~/.brew isn't a standard path for homebrew installations and those are only fully-supported in the default /usr/local location.
@ahupp I use the path ~/homebrew instead of ~/.brew, but it shouldn't really make any difference. In my case I do see libmagic present in the /lib subdir. However, setting the dyld path as you mentioned has no effect. Brew link has no effect.
I did test and DYLD_LIBRARY_PATH worked, but according to this thread it can be stripped unpredictably:
https://github.com/Homebrew/brew/issues/13481#issuecomment-1168598570
I guess the solution then would be to run brew --prefix at import time and search there. Then I (hopefully!) can get rid of the other special cases for homebrew.
@manvento What are the contents of ~/.brew/lib? If libmagic does not appear there, does it appear after running
brew link libmagic?In the next breaking change I'd like to remove the homebrew-specific bits in magic/loader entirely, since the glob for ../Cellar/* is better handled with using
brew linkand standard paths. This just isn't the right layer to solve the problem. Also, AFAICT, ~/.brew isn't a standard path for homebrew installations and those are only fully-supported in the default /usr/local location.
@ahupp , it's already present.
I think that the idea to use brew --prefix at import time can be the better guess for this issue.
@ahupp , I've done the modify you proposed.
Now the program checks if the brew --prefix command exists and, if so, adds the result to the variable paths.
What do you think? It can be merged into the main repo?
Ok, that looks good. Thanks! I'm not in front of a Mac right now but will give it some more testing when I get home.