When I try to build a blockchain transaction using Web3 on python, I'm getting an error that is apparently because I'm using an Apple Silicon computer (2020 M1 MacBook Pro). I'm following a popular Solidity, Blockchain, and Smart Contract course on YouTube and I'm unable to get it working. Could someone please help me out?
My code fails when I try to build a transaction.
The error message I get when I run my code is below:
(myvenv) leonkc@Leons-MacBook-Pro web3_py_simple_storage % python deploy.py
Traceback (most recent call last):
File "/Users/leonkc/solidityDemo/web3_py_simple_storage/deploy.py", line 3, in \<module\>
from web3 import Web3
File "/Users/leonkc/solidityDemo/web3_py_simple_storage/myvenv/lib/python3.9/site-packages/web3/__init__.py", line 6, in \<module\>
from eth_account import (
File "/Users/leonkc/solidityDemo/web3_py_simple_storage/myvenv/lib/python3.9/site-packages/eth_account/__init__.py", line 1, in \<module\>
from eth_account.account import (
File "/Users/leonkc/solidityDemo/web3_py_simple_storage/myvenv/lib/python3.9/site-packages/eth_account/account.py", line 11, in \<module\>
from eth_keyfile import (
File "/Users/leonkc/solidityDemo/web3_py_simple_storage/myvenv/lib/python3.9/site-packages/eth_keyfile/__init__.py", line 7, in \<module\>
from eth_keyfile.keyfile import ( # noqa: F401
File "/Users/leonkc/solidityDemo/web3_py_simple_storage/myvenv/lib/python3.9/site-packages/eth_keyfile/keyfile.py", line 6, in \<module\>
from Crypto.Cipher import AES
File "/Users/leonkc/solidityDemo/web3_py_simple_storage/myvenv/lib/python3.9/site-packages/Crypto/Cipher/__init__.py", line 27, in \<module\>
from Crypto.Cipher.\_mode_ecb import \_create_ecb_cipher
File "/Users/leonkc/solidityDemo/web3_py_simple_storage/myvenv/lib/python3.9/site-packages/Crypto/Cipher/\_mode_ecb.py", line 35, in \<module\>
raw_ecb_lib = load_pycryptodome_raw_lib("Crypto.Cipher.\_raw_ecb", """
File "/Users/leonkc/solidityDemo/web3_py_simple_storage/myvenv/lib/python3.9/site-packages/Crypto/Util/\_raw_api.py", line 309, in load_pycryptodome_raw_lib
raise OSError("Cannot load native module '%s': %s" % (name, ", ".join(attempts)))
OSError: Cannot load native module 'Crypto.Cipher.\_raw_ecb': Not found '\_raw_ecb.cpython-39-darwin.so', Cannot load '\_raw_ecb.abi3.so': dlopen(/Users/leonkc/solidityDemo/web3_py_simple_storage/myvenv/lib/python3.9/site-packages/Crypto/Util/../Cipher/\_raw_ecb.abi3.so, 0x0006): tried: '/Users/leonkc/solidityDemo/web3_py_simple_storage/myvenv/lib/python3.9/site-packages/Crypto/Util/../Cipher/\_raw_ecb.abi3.so' (mach-o file, but is an incompatible architecture (have (x86_64), need (arm64e))), '/Users/leonkc/solidityDemo/web3_py_simple_storage/myvenv/lib/python3.9/site-packages/Crypto/Cipher/\_raw_ecb.abi3.so' (mach-o file, but is an incompatible architecture (have (x86_64), need (arm64e))), Not found '\_raw_ecb.so'
I've tried reinstalling pycryptodome as per another Stack Overflow answer but I still get the same error (with pip install pycryptodome --no-cache-dir --verbose --force-reinstall
)
I'm using a Ganache Ethereum blockchain with an unimportant test address.
Update: I finally ended up fixing this. It was a combination of jeugregg's suggestion here and luchanos's solution in this thread.
That is to say, the things that finally made it work for me were:
python3-intel64
command to run Python instead of just python
pip uninstall pycryptodome
twice) and reinstalling with conda install pycryptodome
(crucial step)pipx install eth-brownie=1.14.6
Python 3.9.5 and brownie version 1.14.6 seem to be the best combination.