pyhunspell / pyhunspell

(Official repo for pypi package) Python bindings for the Hunspell spellchecker engine
https://pypi.python.org/pypi/hunspell
Other
184 stars 36 forks source link

macOS setup.py don't work #67

Open Zacharyyyy opened 5 years ago

Zacharyyyy commented 5 years ago

hunspell version: 1.7.0_2 according top in instruction in https://pypi.org/project/hunspell/, I need to provide the .h location in my system. But I don't know how to check that. All I know is that the libs are store in here /usr/local/Cellar/hunspell/1.7.0_2/lib, and at the moment there are

libhunspell-1.7.0.dylib libhunspell-1.7.dylib   pkgconfig
libhunspell-1.7.a   libhunspell.dylib

I have also tried other method to install it, and I have push another issue for the problems with that. https://github.com/blatinier/pyhunspell/issues/26#issuecomment-508415502

the follow is the error message

running install
running bdist_egg
running egg_info
writing hunspell.egg-info/PKG-INFO
writing dependency_links to hunspell.egg-info/dependency_links.txt
writing top-level names to hunspell.egg-info/top_level.txt
reading manifest file 'hunspell.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'hunspell.egg-info/SOURCES.txt'
installing library code to build/bdist.macosx-10.9-x86_64/egg
running install_lib
running build_ext
building 'hunspell' extension
gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -D_LINUX -I/usr/local/Cellar/hunspell/1.6.2/include/hunspell -I/Library/Frameworks/Python.framework/Versions/3.7/include/python3.7m -c hunspell.cpp -o build/temp.macosx-10.9-x86_64-3.7/hunspell.o -Wall
hunspell.cpp:20:10: fatal error: 'hunspell.hxx' file not found
#include <hunspell.hxx>
         ^~~~~~~~~~~~~~
1 error generated.
error: command 'gcc' failed with exit status 1
Zacharyyyy commented 5 years ago

I cloned the repo and changed main_module_kwargs[‘include_dirs’] in setup.py to /usr/local/Cellar/hunspell/1.7.0_2/include/hunspell And the error message changed, now I can't fund any information to fix it.

11 warnings generated.
creating build/lib.macosx-10.9-x86_64-3.7
g++ -bundle -undefined dynamic_lookup -arch x86_64 -g build/temp.macosx-10.9-x86_64-3.7/hunspell.o -lhunspell -o build/lib.macosx-10.9-x86_64-3.7/hunspell.cpython-37m-darwin.so
ld: library not found for -lhunspell
clang: error: linker command failed with exit code 1 (use -v to see invocation)
error: command 'g++' failed with exit status 1
MayuraVerma commented 5 years ago

I have the same problem

IRNLPCoder commented 5 years ago

have the same issue.

MayuraVerma commented 5 years ago

@blatinier Please review this issue

blatinier commented 5 years ago

I don't own any mac and I won't. I have no knowledge of mac packaging systems, library folders, architecture, etc… I don't see how I can help much… Error message says it doesn't find hunspell header file. So you should ensure that hunspell-dev equivalent for mac is installed. I hope you'll find a solution

x-Code-x commented 5 years ago

I know it's hacky, but setting:

main_module_kwargs = {"sources" : ['absolute/path/to/your/hunspell_dir/in/python/site-packages/hunspell.cpp'], "language": "c++"}

appears to work. Sure it throws more errors (to do with my SDK), but setup finds the file now.

x-Code-x commented 5 years ago

Update: @MayuraVerma @IRNLPCoder by the way: The cause of ld: library not found for -lhunspell appears a lot of the time if you have either a) only installed XCode command line tools without XCode, or b) installed command line tools before installing XCode. (My case is (a).) I can only suggest playing with PATH exports or -L flags - either way, it's out of scope for pyhunspell (and isn't really caused by it) as you are into Hunspell/XCode territory and local variables.

@blatinier by the way - On MacOS, the equivalent of hunspell-dev / header files are automatically installed when you install Hunspell via Homebrew. (Which is why the symlink fix over in #26 always works for people after some messing around - the header files are actually there.)

MayuraVerma commented 5 years ago

@x-Code-x thank you very much. Uninstalling and reinstalling xcode didn't cut the deal. However, updating the hunspell path in setup.py and running it SOLVED the problem.

platform Darwin is mapped to mac os, else didn't cut the deal either.

elif platform.system() == "Darwin":
    main_module_kwargs['define_macros'] = [('_LINUX', None)]
    main_module_kwargs['libraries'] = ['hunspell']
    main_module_kwargs['include_dirs'] = '/usr/local/Cellar/hunspell/1.7.0_2/include/hunspell',
    main_module_kwargs['extra_compile_args'] = ['-Wall']
else:
    main_module_kwargs['define_macros'] = [('_LINUX', None)]
    main_module_kwargs['libraries'] = ['hunspell']
    main_module_kwargs['include_dirs'] = get_linux_include_dirs() + ['/usr/local/Cellar/hunspell/1.7.0_2/include/hunspell']
    main_module_kwargs['extra_compile_args'] = ['-Wall']
BarnabasSzabolcs commented 5 years ago

This change is what I needed for Mac OSX HighSierra 10.13.4 in setup.py:

elif platform.system() == "Darwin":
    main_module_kwargs['define_macros'] = [('_LINUX', None)]
    main_module_kwargs['libraries'] = ['hunspell-1.7']
    main_module_kwargs['include_dirs'] = '/usr/local/Cellar/hunspell/1.7.0_2/include/hunspell',
    main_module_kwargs['library_dirs'] = ['/usr/local/Cellar/hunspell/1.7.0_2/lib']
    main_module_kwargs['extra_compile_args'] = ['-Wall']
deronnax commented 2 years ago

@blatinier macos user here. I managed to get the include error cleanly fixed (using pkg-config), but pkg-config can't help on the library error because it expect a non-version-suffixed library, that hunspell does not (and seemingly) won't provide. Can't we modify the binding so that the built process accepts the version given by pkg-config?

EDIT: If I propose a PR using pkg-config in the setup.py that cleanly fix the problem, will you accept it?

deronnax commented 2 years ago

OK there are actually many PRs trying to solve the problem opened for 2+ years. This project looks abandonned