pyenchant / pyenchant

spellchecking library for python
https://pyenchant.github.io/pyenchant/
GNU Lesser General Public License v2.1
592 stars 97 forks source link

TypeError on Python3, OSX #45

Closed techdragon closed 9 years ago

techdragon commented 9 years ago

The retext project uses pyenchant and somehow the version i have installed seems to fail.

python3 ./retext.py                                                                            
Traceback (most recent call last):
  File "./retext.py", line 24, in <module>
    from ReText import datadirs, globalSettings
  File "/Users/techdragon/dev/sourceforge.com/retext-git/ReText/__init__.py", line 23, in <module>
    import enchant
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/enchant/__init__.py", line 92, in <module>
    from enchant import _enchant as _e
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/enchant/_enchant.py", line 121, in <module>
    prefix_dir.contents = c_char_p(e_dir)
TypeError: bytes or integer address expected instead of str instance

Double checking, the issue is with the python wrapper as i can't get it to work using the wheel just by itself in the python interpreter.

python3                                                                                          1   master
Python 3.4.0 (v3.4.0:04f714765c13, Mar 15 2014, 23:02:41)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import enchant
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/enchant/__init__.py", line 92, in <module>
    from enchant import _enchant as _e
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/enchant/_enchant.py", line 121, in <module>
    prefix_dir.contents = c_char_p(e_dir)
TypeError: bytes or integer address expected instead of str instance
>>>
tarekziade commented 9 years ago

That hack fixed it for me:

prefix_dir.contents = c_char_p(bytes(e_dir, 'utf8'))
smilli commented 9 years ago

I just ran into the same issue on OSX using pyenchant 1.6.6 and Python 3.4.1. The hack above worked for me though.

kersson commented 8 years ago

So... when is 1.6.7 going to be released with this fix? Would love to just pip install pyenchant and have this work :smile:

marshalc commented 8 years ago

I can report the same issue on OSX...

# Sphinx version: 1.4.1
# Python version: 3.5.1 (Python)

# Docutils version: 0.12 release
# Jinja2 version: 2.8
# Last messages:

# Loaded extensions:
Traceback (most recent call last):
  File "/Users/carl/.virtualenvs/guerdon/lib/python3.5/site-packages/sphinx/cmdline.py", line 243, in main
    opts.warningiserror, opts.tags, opts.verbosity, opts.jobs)
  File "/Users/carl/.virtualenvs/guerdon/lib/python3.5/site-packages/sphinx/application.py", line 132, in __init__
    confoverrides or {}, self.tags)
  File "/Users/carl/.virtualenvs/guerdon/lib/python3.5/site-packages/sphinx/config.py", line 289, in __init__
    execfile_(filename, config)
  File "/Users/carl/.virtualenvs/guerdon/lib/python3.5/site-packages/sphinx/util/pycompat.py", line 130, in execfile_
    exec_(code, _globals)
  File "conf.py", line 28, in <module>
    import enchant  # NoQA
  File "/Users/carl/.virtualenvs/guerdon/lib/python3.5/site-packages/enchant/__init__.py", line 92, in <module>
    from enchant import _enchant as _e
  File "/Users/carl/.virtualenvs/guerdon/lib/python3.5/site-packages/enchant/_enchant.py", line 121, in <module>
    prefix_dir.contents = c_char_p(e_dir)
TypeError: bytes or integer address expected instead of str instance

Monkey patching line 121 of lib/python3.5/site-packages/enchant/_enchant.py to prefix_dir.contents = c_char_p(bytes(e_dir, 'utf8')) solved the issue for me, but if this thread is to be believed, this should have been fixed a couple of years ago?

ctb commented 8 years ago

Just hit the same problem as @marshalc today.

Perados commented 8 years ago

I just ran into the same problem as @marshalc as well. (sadpanda)

rfk commented 8 years ago

Hi all, sorry for the radio silence here - I'm not ignoring you, I'm just struggling to make time to fix up my build environment and get the new release pushed out. I don't suppose anyone on this thread has a windows machine and would be able to help out with the build on that platform by any change...?

kersson commented 8 years ago

@rfk sure, let me know what I can do to help.

CoopTheOriginal commented 8 years ago

Can confirm that @tarekziade 's fix does work. It's in line 120 of the _enchant.py file.

kersson commented 8 years ago

@rfk to be clear, I have access to a Windows machine (and OS X and Linux if needed) and am willing to help test.

rfk commented 8 years ago

Hi @kersson, thanks for the offer.

A confession: for the last couple of releases of this project, I haven't been able to re-build the underlying enchant DLLs on windows. Instead what I've been doing is copying the ones from the previous release into the new release. This works OK since we don't need to pull in a new version of the enchant library, but it's pretty gross...

So to get a release out the door, @kersson could you please try this on Windows:

  1. Download the current binary release for windows, and unzip it to get at the packaged dlls etc.
  2. Take a look at the code at [1] which packages dependencies for release, and try to put the resources from the current release into the corresponding locations under ./tools/pyenchant-bdist-win32-sources/.
  3. Run python setup.py bdist_wheel to produce a new binary release for windows, and test whether you can install, import, and use it correctly.

Ugh, I feel kinda gross even just writing that out, but it's what we have to work with currently I'm afraid. The build scripts under ./tools/pyenchant-bdist-win32-sources/ no longer seem to work correctly even when I do have access to a windows machine, and I haven't had a chance to get them back up and running. (Incidentally, that's also why there's no 64-bit windows release published yet).

Of course, anyone who would like to try getting those dependencies building again on windows, would be very very welcome! 😁

[1] https://github.com/rfk/pyenchant/blob/master/setup.py#L138

kersson commented 8 years ago

Haven't forgotten about my offer to help. Hope to get to it this weekend!

kersson commented 8 years ago

Okay, I ran through your steps and things seem to be working alright. I also ran python setup.py test and there were many failures, both for Python 2 and 3, though there were many more for Python 3. That being said, FWIW I tested against my own spell-checker application and it worked both in Python 2 and 3!

I've attached the wheel here, adding a .zip extension to get it upload. Let me know if it looks good!

pyenchant-1.6.7-py2.py3.cp27.cp26.cp32.cp33.cp34.pp27-none-any.whl.zip

kersson commented 8 years ago

Also, I started looking into building enchant from source. Sorry if this is a stupid question, but what build environment do you use? I tried cygwin cross-compiling for mingw32 and was able to build the DLLs, but they wouldn't load when doing import enchant.

rfk commented 8 years ago

@kersson thanks for digging into this! I've been travelling for work, but will put this on top of my stack for testing this week.

what build environment do you use

I used mingw32, but like you, haven't been able to get the compiled dlls to load. I suspect it's some problem with using the pre-built glib dlls but haven't dug into it any further than that.

rfk commented 8 years ago

@kersson thanks again, have finally found the time to take a look at your build, and everything seems correct. Great stuff! I've made a couple of final cleanups and pushed a v1.6.7 tag. When you get a chance, could you please pull and build from that tag, and we can coordinate an upload to PyPI.

tobiasmcnulty commented 7 years ago

FWIW, I stumbled across this issue Googling for this exception. I checked out the 1.6.7 tag and it appears to fix the issue for me.

Note, I originally had a stray version of 1.6.6 installed which caused the same failure the first time I tried it. So if this fix doesn't work for you, make sure you don't have any stray 1.6.6 installs lying around.

tobiasmcnulty commented 7 years ago

@rfk I'd be very grateful for a new PyPI release if/when you have the time!

rfk commented 7 years ago

The latest version has finally been released: https://pypi.python.org/pypi/pyenchant/1.6.7

Thanks for the patience and encouragement here everyone, and @kersson for the help with windows builds!