Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DLL loading issue on Windows #73

Closed
crisbeto opened this issue Feb 19, 2015 · 4 comments · May be fixed by #294
Closed

DLL loading issue on Windows #73

crisbeto opened this issue Feb 19, 2015 · 4 comments · May be fixed by #294

Comments

@crisbeto
Copy link

Recently, I've been having problems getting python-magic to work on Windows. I have libmagic installed, along with all the necessary DLLs (including magic1.dll) but I kept getting Windows 126 errors(module not found). I tried specifying the DLL in the PATH or passing it into the constructor with no luck.

In the end I decided to rename magic1.dll to magic.dll and it started working.
After looking at the source it appears that python-magic tries to load either magic.dll or magic1.dll, however if magic.dll is not found, Windows directly throws an 126 error and doesn't look for magic1.dll. It could be worth considering another, more reliable way of finding the proper DLL.

@ahupp
Copy link
Owner

ahupp commented Feb 20, 2015

You're seeing find_library throw an error? That's not the documented behavior. Can you give a stack trace or error log? I don't have a windows machine to test on but would be happy to get a diff.

@crisbeto
Copy link
Author

Here's the stack trace, I'm not exactly sure whether its find_library that's causing the problem, but its what tipped me off to try and rename the dll:

Traceback (most recent call last):
 File "C:\Python27\lib\site-packages\django\core\management\base.py", line 222, in run_from_argv
   self.execute(*args, **options.__dict__)
 File "C:\Python27\lib\site-packages\django\core\management\base.py", line 250, in execute
   translation.activate('en-us')
 File "C:\Python27\lib\site-packages\django\utils\translation\__init__.py", line 90, in activate
   return _trans.activate(language)
 File "C:\Python27\lib\site-packages\django\utils\translation\trans_real.py", line 183, in activate

   _active.value = translation(language)
 File "C:\Python27\lib\site-packages\django\utils\translation\trans_real.py", line 172, in translat
on
   default_translation = _fetch(settings.LANGUAGE_CODE)
 File "C:\Python27\lib\site-packages\django\utils\translation\trans_real.py", line 154, in _fetch
   app = import_module(appname)
 File "C:\Python27\lib\site-packages\django\utils\importlib.py", line 35, in import_module
   __import__(name)
 File "C:\myproject\sale\__init__.py", line 1, in <module>
   from signals import *
 File "C:\myproject\sale\signals.py", line 9, in <module>
   from main.signals_declaration import soft_delete_done
 File "C:\myproject\main\__init__.py", line 1, in <module>
   from signals import *
 File "C:\myproject\main\signals.py", line 5, in <module>
   from main.MQTasks import mq_sync_deleted_product
 File "C:\myproject\main\MQTasks.py", line 15, in <module>
   from sale.utils import get_language_saxo_code
 File "C:\myproject\sale\utils.py", line 19, in <module>
   from sub_app.utils import parse_bod_error_response, upload_file_to_bod_helper
 File "C:\myproject\sub_app\utils.py", line 24, in <module>
   from main.utils import get_mime_type
 File "C:\myproject\main\utils.py", line 1, in <module>
   import magic
 File "C:\Python27\lib\magic.py", line 155, in <module>
   libmagic = ctypes.CDLL(dll)
 File "C:\Python27\lib\ctypes\__init__.py", line 365, in __init__
   self._handle = _dlopen(self._name, mode)
WindowsError: [Error 126] The specified module could not be found

@MichaelDBA
Copy link

How did you get magic1.dll?

@ahupp
Copy link
Owner

ahupp commented Aug 25, 2023

Merging into #293

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 a pull request may close this issue.

3 participants