Skip to content

Conversation

@manvento
Copy link
Contributor

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

@ahupp
Copy link
Owner

ahupp commented Jun 2, 2022

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.

@manvento
Copy link
Contributor Author

manvento commented Jun 9, 2022

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
Copy link
Contributor Author

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.

@BobDotCom
Copy link

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

BobDotCom added a commit to Pycord-Development/python-magic that referenced this pull request Oct 13, 2022
@ahupp
Copy link
Owner

ahupp commented Oct 17, 2022

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

@BobDotCom
Copy link

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

@ahupp
Copy link
Owner

ahupp commented Oct 18, 2022

I did test and DYLD_LIBRARY_PATH worked, but according to this thread it can be stripped unpredictably:

Homebrew/brew#13481 (comment)

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
Copy link
Contributor Author

@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
Copy link
Contributor Author

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

@ahupp ahupp merged commit cd3929f into ahupp:master Oct 24, 2022
@ahupp
Copy link
Owner

ahupp commented Oct 24, 2022

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 added a commit that referenced this pull request Mar 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants