baking-bad / pytezos

🐍 Python SDK for Tezos | Michelson VM in Python
https://pytezos.org
MIT License
111 stars 36 forks source link

Archlinux Python 3.11 upgrade breaks pip install pytezos #346

Closed tbinetruy closed 9 months ago

tbinetruy commented 1 year ago

Hi,

Not in issue with pytezos per se, but just wanted to let you know that Archlinux has shipped Python 3.11 on community (finally !!!) and that it broke my pytezos installation.

Problem

After doing a system upgrade on Archlinux and upgrading to Python 3.11, installing Pytezos does not throw, but importing it results in:

$ python
Python 3.11.3 (main, Apr  5 2023, 15:52:25) [GCC 12.2.1 20230201] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pytezos
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/tmp/venv/lib/python3.11/site-packages/pytezos/__init__.py", line 13, in <module>
    from pytezos.client import PyTezosClient
  File "/tmp/venv/lib/python3.11/site-packages/pytezos/client.py", line 7, in <module>
    from pytezos.block.header import BlockHeader
  File "/tmp/venv/lib/python3.11/site-packages/pytezos/block/header.py", line 23, in <module>
    from pytezos.sandbox.parameters import protocol_version
  File "/tmp/venv/lib/python3.11/site-packages/pytezos/sandbox/parameters.py", line 74, in <module>
    Key.from_faucet(sandbox_commitment).blinded_public_key_hash(),
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/venv/lib/python3.11/site-packages/pytezos/crypto/key.py", line 317, in from_faucet
    key = cls.from_mnemonic(
          ^^^^^^^^^^^^^^^^^^
  File "/tmp/venv/lib/python3.11/site-packages/pytezos/crypto/key.py", line 292, in from_mnemonic
    _, secret_exponent = pysodium.crypto_sign_seed_keypair(seed=seed[:32])
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/venv/lib/python3.11/site-packages/pytezos/crypto/key.py", line 45, in __getattr__
    raise ImportError(
ImportError: Please, install packages libsodium-dev, libsecp256k1-dev, and libgmp-dev, and Python libraries pysodium, secp256k1, and fastecdsa

This seems to be the problem: https://github.com/baking-bad/pytezos/blob/master/src/pytezos/crypto/key.py#L60

And indeed:

$ python
Python 3.11.3 (main, Apr  5 2023, 15:52:25) [GCC 12.2.1 20230201] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import secp256k1
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/tmp/venv/lib/python3.11/site-packages/secp256k1/__init__.py", line 5, in <module>
    from ._libsecp256k1 import ffi, lib
ImportError: /tmp/venv/lib/python3.11/site-packages/secp256k1/_libsecp256k1.cpython-311-x86_64-linux-gnu.so: undefined symbol: secp256k1_keypair_xonly_pub

Fix

install libsecp256k1 from AUR rather than community as otherwise, secp256k1-py will not find the needed symbols in the shared library:

# remove community libsecp256k1
sudo pacman -R libsecp256k1

# install from AUR
yay -S libsecp256k1-git

# install secp256k1-py without the binaries
pip install --no-binary :all: secp256k1

# install pytezos
pip install pytezos

Thanks @jpic for finding the fix, he's filed a bug on Archlinux to propose a fix: https://bugs.archlinux.org/task/78420 where more information is provided.

m-kus commented 1 year ago

Hey! Noted, thank you for investigating this!

tbinetruy commented 9 months ago

Closing as the fix was implemented and the problem does not occur anymore: https://bugs.archlinux.org/task/78420.