python-magic icon indicating copy to clipboard operation
python-magic copied to clipboard

added path for local homebrew installation

Open manvento opened this issue 3 years ago • 3 comments

I wrote this little fix in order to access libmagic in mac even if it's installed with brew on user's home folder.

manvento avatar May 23 '22 07:05 manvento

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.

ahupp avatar Jun 02 '22 14:06 ahupp

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.

manvento avatar Jun 09 '22 09:06 manvento

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.

manvento avatar Jul 13 '22 13:07 manvento

I'm having this issue as well. A fix would be great :)

BobDotCom avatar Oct 13 '22 18:10 BobDotCom

@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 avatar Oct 17 '22 23:10 ahupp

@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.

BobDotCom avatar Oct 18 '22 14:10 BobDotCom

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.

ahupp avatar Oct 18 '22 19:10 ahupp

@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 , it's already present.

I think that the idea to use brew --prefix at import time can be the better guess for this issue.

manvento avatar Oct 20 '22 06:10 manvento

@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?

manvento avatar Oct 21 '22 17:10 manvento

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.

ahupp avatar Oct 24 '22 15:10 ahupp