By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,230 Members | 2,471 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,230 IT Pros & Developers. It's quick & easy.

Ctypes Error: Why can't it find the DLL.

P: n/a
Hi,

I can't figure out why ctypes won't load the DLL I need to use. I've
tried everything I can find (and the ctypes website is down at the
moment). Here's what I've seen so far.

I've added the file arapi51.dll to the system32 directory. However
when I tried to access it I see this:
>>print windll.arapi51 # doctest: +WINDOWS
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
File "C:\Python24\Lib\site-packages\ctypes\__init__.py", line 387, in
__getattr__
dll = self._dlltype(name)
File "C:\Python24\Lib\site-packages\ctypes\__init__.py", line 312, in
__init__
self._handle = _dlopen(self._name, mode)
WindowsError: [Errno 126] The specified module could not be found

So then I use the find_library function, and it finds it:
>>find_library('arapi51.dll')
'C:\\WINNT\\system32\\arapi51.dll'

At that point I try to use the LoadLibrary function, but it still can't
find it:
>>windll.LoadLibrary('C:\WINNT\system32\arapi51.dl l')
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
File "C:\Python24\Lib\site-packages\ctypes\__init__.py", line 395, in
LoadLibrary
return self._dlltype(name)
File "C:\Python24\Lib\site-packages\ctypes\__init__.py", line 312, in
__init__
self._handle = _dlopen(self._name, mode)
WindowsError: [Errno 126] The specified module could not be found

What am I doing wrong? I've used ctypes before and not had this
problem. Before, I've just added the file to the system32 directory and
not had this problem.

On another note, if I wanted to include these DLL's to be a part of an
installable package, how would I configure ctypes to use DLL's from a
local directory?

Thanks,
Marc

Oct 24 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Mudcat a écrit :
Hi,

I can't figure out why ctypes won't load the DLL I need to use. I've
tried everything I can find (and the ctypes website is down at the
moment). Here's what I've seen so far.

I've added the file arapi51.dll to the system32 directory. However
when I tried to access it I see this:
(snip)
WindowsError: [Errno 126] The specified module could not be found

So then I use the find_library function, and it finds it:
(snip)
At that point I try to use the LoadLibrary function, but it still can't
find it:
(snip)
WindowsError: [Errno 126] The specified module could not be found

What am I doing wrong? I've used ctypes before and not had this
problem. Before, I've just added the file to the system32 directory and
not had this problem.
Looks like it could have to do with another dll arapi51.dll depends upon
that would be missing, cf:
http://aspn.activestate.com/ASPN/Mai...-users/2593616

HTH
Oct 24 '06 #2

P: n/a
"Mudcat" <mn******@gmail.comwrites:

Is the DLL loadable from a standalone C program?
All that is needed is a call to LoadLibrary() and check the return.

If the full path is not specified, the dll is searched in the predefined order
- I believe it is
executable directory - in this case, directory of python.exe
current directory - set the current drive and path to whereever you want
before trying to load the dll
windows system directory
windows directory
Directories specified in PATH evnvironment variable

-Chetan
Hi,

I can't figure out why ctypes won't load the DLL I need to use. I've
tried everything I can find (and the ctypes website is down at the
moment). Here's what I've seen so far.

I've added the file arapi51.dll to the system32 directory. However
when I tried to access it I see this:
>>>print windll.arapi51 # doctest: +WINDOWS
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
File "C:\Python24\Lib\site-packages\ctypes\__init__.py", line 387, in
__getattr__
dll = self._dlltype(name)
File "C:\Python24\Lib\site-packages\ctypes\__init__.py", line 312, in
__init__
self._handle = _dlopen(self._name, mode)
WindowsError: [Errno 126] The specified module could not be found

So then I use the find_library function, and it finds it:
>>>find_library('arapi51.dll')
'C:\\WINNT\\system32\\arapi51.dll'

At that point I try to use the LoadLibrary function, but it still can't
find it:
>>>windll.LoadLibrary('C:\WINNT\system32\arapi51.d ll')
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
File "C:\Python24\Lib\site-packages\ctypes\__init__.py", line 395, in
LoadLibrary
return self._dlltype(name)
File "C:\Python24\Lib\site-packages\ctypes\__init__.py", line 312, in
__init__
self._handle = _dlopen(self._name, mode)
WindowsError: [Errno 126] The specified module could not be found

What am I doing wrong? I've used ctypes before and not had this
problem. Before, I've just added the file to the system32 directory and
not had this problem.

On another note, if I wanted to include these DLL's to be a part of an
installable package, how would I configure ctypes to use DLL's from a
local directory?

Thanks,
Marc
Oct 25 '06 #3

P: n/a

Mudcat wrote:

So then I use the find_library function, and it finds it:
>find_library('arapi51.dll')
'C:\\WINNT\\system32\\arapi51.dll'
Notice it's escaped the '\' character.
At that point I try to use the LoadLibrary function, but it still can't
find it:
>windll.LoadLibrary('C:\WINNT\system32\arapi51.dll ')
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
File "C:\Python24\Lib\site-packages\ctypes\__init__.py", line 395, in
LoadLibrary
return self._dlltype(name)
File "C:\Python24\Lib\site-packages\ctypes\__init__.py", line 312, in
__init__
self._handle = _dlopen(self._name, mode)
WindowsError: [Errno 126] The specified module could not be found

What am I doing wrong? [snip]
You need to use either
windll.LoadLibrary(r'c:\winnt\system32\arapi51.dll ') or escape the \'s
as the find_library function did. You're getting caught out by \a which
is the alert/bell character. \w and \s aren't valid escape sequences so
you get away with them. I'm guessing it's worked before because you've
been lucky.

Works fine!:
>>'C:\winnt\system32\smtpctrs.dll'
'C:\\winnt\\system32\\smtpctrs.dll'

Uh oh, escaped:
>>'C:\winnt\system32\arapi51.dll'
'C:\\winnt\\system32\x07rapi51.dll'

Jon.

Oct 25 '06 #4

P: n/a
"Jon Clements" <jo****@googlemail.comwrites:
Mudcat wrote:

So then I use the find_library function, and it finds it:
>>find_library('arapi51.dll')
'C:\\WINNT\\system32\\arapi51.dll'

Notice it's escaped the '\' character.
At that point I try to use the LoadLibrary function, but it still can't
find it:
>>windll.LoadLibrary('C:\WINNT\system32\arapi51.dl l')
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
File "C:\Python24\Lib\site-packages\ctypes\__init__.py", line 395, in
LoadLibrary
return self._dlltype(name)
File "C:\Python24\Lib\site-packages\ctypes\__init__.py", line 312, in
__init__
self._handle = _dlopen(self._name, mode)
WindowsError: [Errno 126] The specified module could not be found

What am I doing wrong? [snip]

You need to use either
windll.LoadLibrary(r'c:\winnt\system32\arapi51.dll ') or escape the \'s
as the find_library function did. You're getting caught out by \a which
is the alert/bell character. \w and \s aren't valid escape sequences so
you get away with them. I'm guessing it's worked before because you've
been lucky.

Works fine!:
>'C:\winnt\system32\smtpctrs.dll'
'C:\\winnt\\system32\\smtpctrs.dll'

Uh oh, escaped:
>'C:\winnt\system32\arapi51.dll'
'C:\\winnt\\system32\x07rapi51.dll'
I wondered about it, but that would not explain why it fails in the first case
- perhaps the OP now knows what happened. Interestingly I get a different
error with the distribution binary for 2.5 - I get "Error 22" instead of "Errno
126", but the message text was same, so I assumed this was from a different
version and something had changed about how the errno is reported.

However, I checked the windows error codes and 126 seems to be the correct
error. The error code talks about bad command and the corresponding message
text reads "The device does not recognize the command."

-Chetan
>
Jon.
Oct 25 '06 #5

P: n/a
That was it. Once I added the other DLLs then it was able to find and
make the call.

Thanks for all the help,
Marc
Bruno Desthuilliers wrote:
Mudcat a écrit :
Hi,

I can't figure out why ctypes won't load the DLL I need to use. I've
tried everything I can find (and the ctypes website is down at the
moment). Here's what I've seen so far.

I've added the file arapi51.dll to the system32 directory. However
when I tried to access it I see this:
(snip)
WindowsError: [Errno 126] The specified module could not be found

So then I use the find_library function, and it finds it:
(snip)
At that point I try to use the LoadLibrary function, but it still can't
find it:
(snip)
WindowsError: [Errno 126] The specified module could not be found

What am I doing wrong? I've used ctypes before and not had this
problem. Before, I've just added the file to the system32 directory and
not had this problem.

Looks like it could have to do with another dll arapi51.dll depends upon
that would be missing, cf:
http://aspn.activestate.com/ASPN/Mai...-users/2593616

HTH
Oct 28 '06 #6

P: n/a
Mudcat a écrit :
That was it. Once I added the other DLLs then it was able to find and
make the call.

Thanks for all the help,
I just googled for "WindowsError: [Errno 126]" and followed the links,
you know...
Oct 31 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.