Skip to content

Issues with finding 'cygmagic-1'  #87

Closed

Description

@jakubczaplicki

Environment: Windows 7, Python 2.7, Most recent Cygwin x86 (DLL 2.2.1-1)

OK. So I got python-magic running only after moving the Cygwin PATH to the beginning of the %PATH% env.var. :

1. Install the cygwin-libmagic in Cygwin 
2. Install https://github.com/ahupp/python-magic (python setup.py install)
3. Place c:\cygwin\bin\   right at the beginning of PATH env.var. 
4. Open python, import magic

Without the step 3 I got:

   >>> import magic
   Traceback (most recent call last):
     File "<stdin>", line 1, in <module>
     File "C:\Python27\lib\site-packages\magic.py", line 184, in <module>
       raise ImportError('failed to find libmagic.  Check your installation')
   ImportError: failed to find libmagic.  Check your installation

and:

    >>> import ctypes
    >>> import ctypes.util
    >>> print ctypes.util.find_library('cygmagic-1')
    None
    >>> print ctypes.util.find_library('c')
    msvcr90.dll

It looks like the find_library() method can’t be bothered to look for the libs in other places from the %PATH%. The dll it finds is in a Webex folder...

Once I've put c:\cygwin\bin at the beginning of %PATH%, all my life problems were immediately solved :

   >>> import ctypes.util
   >>> ctypes.util.find_library('cygmagic-1')
   'c:\\cygwin\\bin\\cygmagic-1.dll'
   >>> import os
   >>> os.getenv("PATH")
   'c:\\cygwin\\bin\\;C:\\Python27\\;C:\\Python27\\Scripts; <snip>

So I wanted to check if it really was causing the problem, moved the path to Cygwin back to the end of %PATH%, rerun cmd and opened python console, and guess what ? It still works ! Why ? :

   >>> import ctypes.util
   >>> ctypes.util.find_library('cygmagic-1')
   'c:\\cygwin\\bin\\cygmagic-1.dll'
   >>> import os
   >>> os.getenv("PATH")
   <snap>;C:\\Program Files (x86)\\gnuplot\\bin;c:\\cygwin\\bin'

Activity

  1. ahupp commented on Sep 12, 2015

    @ahupp
    Owner

    Hah, I have no idea. The dll load path stuff is mysterious (i don't actually own a windows machine). If you find a good solution please submit it and I'll add to the docs.

  2. ahupp commented on Sep 12, 2015

    @ahupp
    Owner

    Or rather, find an answer. It's hard to imagine that the position in the path really effects this.

  3. ahupp commented on Apr 26, 2016

    @ahupp
    Owner

    Does it find the lib if you put that path in /etc/ld.so.conf and re-run ldconfig? I don't understand your proposal. Libraries should not be handling command line args.

  4. ahupp commented on Apr 26, 2016

    @ahupp
    Owner

    What is "link time" in this context though? In python we don't really have that distinction. I'm tempted to just define an env variable that people can defined to override the location then I can get rid of all the janky platform-specific paths. Would be a breaking change though.

  5. ahupp commented on Aug 25, 2023

    @ahupp
    Owner

    Merging into #293

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions