openvenues / libpostal

A C library for parsing/normalizing street addresses around the world. Powered by statistical NLP and open geo data.
MIT License
4.06k stars 417 forks source link

M1 Mac woes using libpostal #585

Open bdiller-interos opened 2 years ago

bdiller-interos commented 2 years ago

Hi!

I tried installing libpostal on M1 Mac through these two methods listed below: 1) https://github.com/openvenues/libpostal#installation-maclinux 2) https://ports.macports.org/port/libpostal

I cannot use the parser api using the python bindings when library is installed by (1) or (2).

For example, after I installed the postal package in my python 3.8.6 virtual environment, i.e.,pip install postal, I am receiving this consistent error when doing a simple import :

venv) libpostal % python Python 3.8.6 (v3.8.6:db455296be, Sep 23 2020, 13:31:39) [Clang 6.0 (clang-600.0.57)] on darwin Type "help", "copyright", "credits" or "license" for more information.

from postal.parser import parse_address Traceback (most recent call last): File "", line 1, in File "/Users/bdiller/gitlab/project/venv/lib/python3.8/site-packages/postal/parser.py", line 2, in from postal import _parser ImportError: dlopen(/Users/bdiller/gitlab/project/venv/lib/python3.8/site-packages/postal/_parser.cpython-38-darwin.so, 0x0002): symbol not found in flat namespace '_libpostal_address_parser_response_destroy'

What is wrong?

JochenFromm commented 2 years ago

What you can do:

If it still does not work try to use Python 3.9 or 3.10. I was able to get it working by switching from 3.8 to 3.9 or 3.10. Then the nasty error message "symbol not found in flat namespace '_libpostal_address_parser_response_destroy'" went away.

Gayathri2993 commented 1 year ago

What you can do:

If it still does not work try to use Python 3.9 or 3.10. I was able to get it working by switching from 3.8 to 3.9 or 3.10. Then the nasty error message "symbol not found in flat namespace '_libpostal_address_parser_response_destroy'" went away.

I have tried the mentioned steps but it still dint work. My arch is 'AMD64'. I have also tried swithcing to 3.9. It still doesnt work. Any help on this would be appreciated

varunpawar652000 commented 1 year ago

I am facing the same issue with M2 Mac I tried using all the methods but it does not work out for me if @albarrentine or @JochenFromm or anyone who could help to resolve this issue is really appreciated.

brianmacy commented 1 year ago

% gcc -v Apple clang version 14.0.3 (clang-1403.0.22.14.1) Target: arm64-apple-darwin22.5.0 Thread model: posix InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

Here is exactly what I did and make check succeeds:

brew install curl autoconf automake libtool pkg-config
mkdir test
cd test
git clone https://github.com/openvenues/libpostal
cd libpostal
./bootstrap.sh
./configure --datadir=/tmp/libpostal --prefix=$PWD MODEL=senzing
make -j16 install
make check

I tried --disable-sse2 like configure suggests but it looks like someone auto-detected the ARM architecture to disable that automatically and if you actually specify --disable-sse2 it breaks things. I have an M1 but I doubt that matters here.

varunpawar652000 commented 1 year ago

This works for me. Thanks ❤️ Could you also help me in that how I can use it for python.

>>> from postal import _parser
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: dlopen(/Users/varunpawar/.pyenv/versions/3.8.13/lib/python3.8/site-packages/postal/_parser.cpython-38-darwin.so, 0x0002): tried: '/Users/varunpawar/.pyenv/versions/3.8.13/lib/python3.8/site-packages/postal/_parser.cpython-38-darwin.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/Users/varunpawar/.pyenv/versions/3.8.13/lib/python3.8/site-packages/postal/_parser.cpython-38-darwin.so' (no such file), '/Users/varunpawar/.pyenv/versions/3.8.13/lib/python3.8/site-packages/postal/_parser.cpython-38-darwin.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64'))
brianmacy commented 1 year ago

Run file /Users/varunpawar/.pyenv/versions/3.8.13/lib/python3.8/site-packages/postal/_parser.cpython-38-darwin.so

Then the same on the python executable that you are running. It looks like the postal binaries that you installed with pip are Intel x86_64 and your python is arm64. Make sure your pip is also arm64 as that would be required for you to get the right Python packages... though I really have no experience with the Python bindings, so can't help. You might want to file an issue on that project (I think it is separate).

wiseyoungbuck commented 1 year ago

I have the same issue. Will not run in python 3.7 or 3.8, works with 3.9. I am using python in a conda environment. I attempted to solve this using both Rosetta and Native terminals as well as Rosetta and Native Homebrew. The--disable-sse2 flag did not work for me, but upgrading to python 3.9 then doing a pip install did solve the problem.

On a Mac M2 Max. % gcc -v Apple clang version 14.0.3 (clang-1403.0.22.14.1) Target: x86_64-apple-darwin22.5.0 Thread model: posix InstalledDir: /Library/Developer/CommandLineTools/usr/bin

varunpawar652000 commented 1 year ago

Main reason is pypostal uses a particular includes and bin directory and for Mac some times that would not be that we have in pypostal. So to resolve the issue I install python 3.10 and tweaked my path for libpostal includes and bin.

nikil-katturi commented 1 year ago

i am using pyspark and getting below error on mac M1. i tired to use python 3.9 version too . It is working with python but not with pyspark : ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/postal/_parser.cpython-310-darwin.so, 0x0002): symbol not found in flat namespace '_libpostal_address_parser_response_destroy'

@varunpawar652000 can you share on how you set the path ?

varunpawar652000 commented 1 year ago

@nikil-katturi can you please share your python version?

nikil-katturi commented 1 year ago

python version 3.10

varunpawar652000 commented 1 year ago

Is pypostal is working as you want? Like with out pyspark are you able to use pypostal?

nikil-katturi commented 1 year ago

yes it is working without pyspark

rluba commented 6 days ago

You can avoid Rosetta and build libpostal natively for Apple Silicon macs (M1 etc.), too. Here’s how I did it:

export CC=clang
export CXX=clang++
./configure --datadir=<your_dir_of_choice> --disable-sse2
make
sudo make install
make check

Checking the result:

> file /usr/local/lib/libpostal.dylib
/usr/local/lib/libpostal.dylib: Mach-O 64-bit dynamically linked shared library arm64