Re: Unable to import NHunspell.dll using ctypes in Python

2013-06-25 Thread Mark Lawrence

On 25/06/2013 07:23, akshay.k...@gmail.com wrote:



Im required to import ha certain dll called 'NHunspell.dll' which is used for 
Spell Checking purposes. I am using Python for the software. Although I checked 
out several websites to properly use ctypes, I have been unable to load the dll 
properly.

When I use this code.

   from ctypes import *
   hunspell = cdll.LoadLibrary['Hunspellx64.dll']

I get an error

   hunspell = cdll.LoadLibrary['Hunspellx64.dll']
   TypeError: 'instancemethod' object has no attribute '__getitem__'

I guess it might a problem with the structure of the dll. But I have no idea 
how to import the dll properly.



 from ctypes import *
 help(cdll.LoadLibrary)
Help on method LoadLibrary in module ctypes:

LoadLibrary(self, name) method of ctypes.LibraryLoader instance.

So looks as if you need:-

hunspell = cdll.LoadLibrary('Hunspellx64.dll')

--
Steve is going for the pink ball - and for those of you who are 
watching in black and white, the pink is next to the green. Snooker 
commentator 'Whispering' Ted Lowe.


Mark Lawrence

--
http://mail.python.org/mailman/listinfo/python-list


Re: Unable to import NHunspell.dll using ctypes in Python

2013-06-25 Thread akshay . ksth
Thanks for the reply Mark. I did what you suggested. 
But now I'm getting an error like this.

Traceback (most recent call last):
  File start.py, line 15, in module
hunspell = cdll.LoadLibrary('/home/kuro/Desktop/notepad/Hunspellx64.dll')
  File /usr/lib/python2.7/ctypes/__init__.py, line 443, in LoadLibrary
return self._dlltype(name)
  File /usr/lib/python2.7/ctypes/__init__.py, line 365, in __init__
self._handle = _dlopen(self._name, mode)
OSError: /home/kuro/Desktop/notepad/Hunspellx64.dll: invalid ELF header

I am really new to using ctypes and dll files. Can you please guide me out. 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unable to import NHunspell.dll using ctypes in Python

2013-06-25 Thread Dave Angel

On 06/25/2013 03:32 AM, akshay.k...@gmail.com wrote:

Thanks for the reply Mark. I did what you suggested.
But now I'm getting an error like this.

Traceback (most recent call last):
   File start.py, line 15, in module
 hunspell = cdll.LoadLibrary('/home/kuro/Desktop/notepad/Hunspellx64.dll')
   File /usr/lib/python2.7/ctypes/__init__.py, line 443, in LoadLibrary
 return self._dlltype(name)
   File /usr/lib/python2.7/ctypes/__init__.py, line 365, in __init__
 self._handle = _dlopen(self._name, mode)
OSError: /home/kuro/Desktop/notepad/Hunspellx64.dll: invalid ELF header

I am really new to using ctypes and dll files. Can you please guide me out.



This is why it's frequently useful to supply the information with your 
original question:  what version of Python, and what OS.


You're on Linux or similar, and dll's are the way a Windows executable 
is named.  So chances are you're trying to install a Windows dll on 
Linux, which is unlikely to work except under very special circumstances 
(eg. within WINE).


Try going back to where you downloaded this file, and see if you can get 
the one for your OS.


--
DaveA
--
http://mail.python.org/mailman/listinfo/python-list


Re: Unable to import NHunspell.dll using ctypes in Python

2013-06-25 Thread Chris “Kwpolska” Warrick
On Tue, Jun 25, 2013 at 9:45 AM, Dave Angel da...@davea.name wrote:
 You're on Linux or similar, and dll's are the way a Windows executable is
 named.

dll’s are libraries for windows, not executables (/lib not /bin)

 Try going back to where you downloaded this file, and see if you can get the
 one for your OS.

That is not necessary.  Because it is a sane OS, it is likely that
hunspell is packaged in the repositories of OP’s system, and might be
even installed there.  And if the package is installed, hunspell
should reside in /usr/lib/libhunspell.so or a similar place.
--
Kwpolska http://kwpolska.tk | GPG KEY: 5EAAEA16
stop html mail| always bottom-post
http://asciiribbon.org| http://caliburn.nl/topposting.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unable to import NHunspell.dll using ctypes in Python

2013-06-25 Thread akshay . ksth
Thanks Dave. 
I'm using Python 2.7 and am working on Linux Mint. 
Does it mean that I cant load the functions within the dll whilst on Linux. I 
thought that was what ctypes was used for.

Please correct me if I misunderstood what you meant.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unable to import NHunspell.dll using ctypes in Python

2013-06-25 Thread akshay . ksth
On Tuesday, June 25, 2013 12:08:17 PM UTC+5:45, aksha...@gmail.com wrote:
 Im required to import ha certain dll called 'NHunspell.dll' which is used for 
 Spell Checking purposes. I am using Python for the software. Although I 
 checked out several websites to properly use ctypes, I have been unable to 
 load the dll properly.
 
 
 
 When I use this code.
 
 
 
   from ctypes import *
 
   hunspell = cdll.LoadLibrary['Hunspellx64.dll']
 
 
 
 I get an error
 
 
 
   hunspell = cdll.LoadLibrary['Hunspellx64.dll']
 
   TypeError: 'instancemethod' object has no attribute '__getitem__'
 
 
 
 I guess it might a problem with the structure of the dll. But I have no idea 
 how to import the dll properly.

@Chris 
I understand that. But then I am supposed to create something that works on a 
Windows environment using a Windows Dll.Aaandd Im stuck. 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unable to import NHunspell.dll using ctypes in Python

2013-06-25 Thread Chris “Kwpolska” Warrick
On Tue, Jun 25, 2013 at 10:04 AM,  akshay.k...@gmail.com wrote:
 @Chris
 I understand that. But then I am supposed to create something that works on a 
 Windows environment using a Windows Dll.Aaandd Im stuck.
 --
 http://mail.python.org/mailman/listinfo/python-list

Then you need to get your hands on a copy of Windows.  Or try messing
with Wine (you would need to install the Python interpreter for
Windows there), but that might not work properly.

And ctypes is used to use functions provided by C libraries on your
system, that is .dll files on Windows and .so files (shared object
files) everywhere else.

--
Kwpolska http://kwpolska.tk | GPG KEY: 5EAAEA16
stop html mail| always bottom-post
http://asciiribbon.org| http://caliburn.nl/topposting.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unable to import NHunspell.dll using ctypes in Python

2013-06-25 Thread Dave Angel

On 06/25/2013 03:54 AM, Chris “Kwpolska” Warrick wrote:

On Tue, Jun 25, 2013 at 9:45 AM, Dave Angel da...@davea.name wrote:

You're on Linux or similar, and dll's are the way a Windows executable is
named.


dll’s are libraries for windows, not executables (/lib not /bin)


Try going back to where you downloaded this file, and see if you can get the
one for your OS.


That is not necessary.  Because it is a sane OS, it is likely that
hunspell is packaged in the repositories of OP’s system, and might be
even installed there.  And if the package is installed, hunspell
should reside in /usr/lib/libhunspell.so or a similar place.


Sorry, since I was talking about a DLL, I used Microsoft's terminology. 
 Certainly in Unix terms, a DLL is roughly equivalent to a shared library.


DLL is one of the dozens of file extensions commonly used for Microsoft 
executables, or PE files.  Microsoft doesn't generally make the 
distinction between an executable which can be called from the command 
line and one which can only be used with LoadLibraryEx().  In common 
use, only the main executable of a program will have an entry point, 
but both common types may be used for library code.


http://msdn.microsoft.com/en-us/library/windows/hardware/gg463119.aspx


As for finding it in the repository, you're certainly right.  I had 
naiively assumed that the OP would have looked there first, and wouldn't 
be in this state if it were in the repository (eg. Synaptic).  It is in 
Ubuntu 12.04.





--
DaveA
--
http://mail.python.org/mailman/listinfo/python-list


Re: Unable to import NHunspell.dll using ctypes in Python

2013-06-25 Thread Dave Angel

On 06/25/2013 03:58 AM, akshay.k...@gmail.com wrote:

Thanks Dave.
I'm using Python 2.7 and am working on Linux Mint.
Does it mean that I cant load the functions within the dll whilst on Linux. I 
thought that was what ctypes was used for.

Please correct me if I misunderstood what you meant.



ctypes is not for cross-platform development, it's for cross-language 
development.  If you have a shared library for your own system whose 
interfaces are designed for a static-typed language (usually C), ctypes 
lets you bridge the gap, and call it from Python.


Your best bet is probably either to find a Windows machine, or to run an 
actual Windows inside a Virtual Box.  I do that whenever I have to 
support an application that's not available for Linux.  In either case, 
you're actually running Windows, so you'll need a Windows python, which 
knows how to call the Windows LoadLibrary and getProcAddress and other 
such OS-specific interfaces.


There's a possibility that running a Windows version of Python under 
WINE will work to access a Windows DLL, but the likelihood is so high 
that there'll be inconsistencies that I wouldn't bother.


VirtualBox and WINE are both available in most Linuxes, for example in 
Synaptic.  And they should also be available via apt-get, but I don't 
know how to find them that way.


--
DaveA
--
http://mail.python.org/mailman/listinfo/python-list


Re: Unable to import NHunspell.dll using ctypes in Python

2013-06-25 Thread akshay . ksth
Thanks everyone. But it still did not work. I instead used a Python wrapper for 
Hunspell called Pyhunspell. The actual link in PyPi does not work for Python 
2.7 but it has been improved and upgraded in 
[here](https://github.com/akshaylb/nepali-spellchecker-v2/tree/master/pyhunspell).
-- 
http://mail.python.org/mailman/listinfo/python-list