matrix-org / olm

An implementation of the Double Ratchet cryptographic ratchet in C++/C
https://gitlab.matrix.org/matrix-org/olm
63 stars 9 forks source link

Error loading native lib from python #85

Open xvolks opened 1 year ago

xvolks commented 1 year ago

After install in a new venv with pip install python-olm==3.2.15

I get the message error symbol not found in flat namespace '__olm_error_to_string'

Tested with python 3.9, 3.10 and 3.11 on macOS 14.

❯ python
Python 3.10.12 (main, Jun 20 2023, 19:43:52) [Clang 14.0.3 (clang-1403.0.22.14.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import olm
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/Shared/bot/venv/lib/python3.10/site-packages/olm/__init__.py", line 24, in <module>
    from .utility import ed25519_verify, OlmVerifyError, OlmHashError, sha256
  File "/Users/Shared/bot/venv/lib/python3.10/site-packages/olm/utility.py", line 37, in <module>
    from _libolm import ffi, lib  # type: ignore
ImportError: dlopen(/Users/Shared/bot/venv/lib/python3.10/site-packages/_libolm.abi3.so, 0x0002): symbol not found in flat namespace '__olm_error_to_string'
uhoreg commented 1 year ago

Seems to work as expected on Linux. Strangely, _olm_error_to_string is only used internally, so there shouldn't be any linking errors.

Installing using libolm from brew, and older python package works, so there's something strange with the current build process on macOS.

xvolks commented 1 year ago

As a temporary workaround @uhoreg told me to install:

brew install libolm
pip3 install python-olm==3.1.3 --global-option="build_ext" --global-option="--include-dirs="`brew --prefix libolm`"/include" --global-option="--library-dirs="`brew --prefix libolm`"/lib"

Remember to remove the version 3.2.15 if necessary.

It worked for me.

NiTRoeSE commented 1 year ago

I have the same issue on macOS 14 and python3.11 ( i dont have it tested with another python version):

brew install libolm pip3 install matrix-nio


Traceback (most recent call last):
  File "/Users/nitro/Medialyse-Git/JSP Chat/main.py", line 10, in <module>
    from nio import AsyncClient, LoginResponse
  File "/Users/nitro/Medialyse-Git/JSP Chat/.jspchat_venv/lib/python3.11/site-packages/nio/__init__.py", line 9, in <module>
    from .client import *
  File "/Users/nitro/Medialyse-Git/JSP Chat/.jspchat_venv/lib/python3.11/site-packages/nio/client/__init__.py", line 3, in <module>
    from .base_client import Client, ClientConfig
  File "/Users/nitro/Medialyse-Git/JSP Chat/.jspchat_venv/lib/python3.11/site-packages/nio/client/base_client.py", line 36, in <module>
    from ..crypto import ENCRYPTION_ENABLED, DeviceStore, OutgoingKeyRequest
  File "/Users/nitro/Medialyse-Git/JSP Chat/.jspchat_venv/lib/python3.11/site-packages/nio/crypto/__init__.py", line 25, in <module>
    from .sessions import (  # isort:skip
  File "/Users/nitro/Medialyse-Git/JSP Chat/.jspchat_venv/lib/python3.11/site-packages/nio/crypto/sessions.py", line 21, in <module>
    import olm
  File "/Users/nitro/Medialyse-Git/JSP Chat/.jspchat_venv/lib/python3.11/site-packages/olm/__init__.py", line 24, in <module>
    from .utility import ed25519_verify, OlmVerifyError, OlmHashError, sha256
  File "/Users/nitro/Medialyse-Git/JSP Chat/.jspchat_venv/lib/python3.11/site-packages/olm/utility.py", line 37, in <module>
    from _libolm import ffi, lib  # type: ignore
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ImportError: dlopen(/Users/nitro/Medialyse-Git/JSP Chat/.jspchat_venv/lib/python3.11/site-packages/_libolm.abi3.so, 0x0002): symbol not found in flat namespace '__olm_error_to_string'

The mentioned workaround didnt work for me:

pip3 install python-olm==3.1.3 --global-option="build_ext" --global-option="--include-dirs="`brew --prefix libolm`"/include" --global-option="--library-dirs="`brew --prefix libolm`"/lib"

Update: Same error with python3.8

Hope someone can help, thanks in advanced!