Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Electrum fails to start Raspberry Pi OS 10 Buster #8081

Closed
flyerbear opened this issue Nov 22, 2022 · 8 comments
Closed

Electrum fails to start Raspberry Pi OS 10 Buster #8081

flyerbear opened this issue Nov 22, 2022 · 8 comments

Comments

@flyerbear
Copy link

flyerbear commented Nov 22, 2022

I'm trying to run Electrum 4.3.2 on a Raspberry Pi 4 running RPi OS 10 / buster. I know this is an old OS version but I need to use it for another part of this project that will eventually be run on an RPi Zero. I've upgraded Python to 3.8.15, installed all dependencies per electrum.org and am trying to run Electrum without installing. I get the following errors whenever I try to launch it:

Traceback most (recent call last)
File "./run_electrum", line 88, in <module>
    check_imports()
File "./run_electrum", line 81, in check_imports
    from google.protobuf import reflection
File "/home/pi/Downloads/Electrum-4.3.2/packages/google/protobuf/reflection.py", line 51, in <module>
    from google.protobuf import message_factory
File "/home/pi/Downloads/Electrum-4.3.2/packages/google/protobuf/message_factory.py", line 49, in <module>
    from google.protobuf.internal import python_message as message_impl
File "/home/pi/Downloads/Electrum-4.3.2/packages/google/protobuf/internal/python _message.py", line 64, in <module>
    from google.protobuf.internal import extension_dict
File "/home/pi/Downloads/Electrum-4.3.2/packages/google/protobuf/internal/extension_dict.py", line 34, in <module>
    from google-protobuf.internal import type_checkers
File "/home/pi/Downloads/Electrum-4.3.2/packages/google/protobuf/internal/type_checkers.py", line 48, in <module>
    import ctypes
File "/usr/local/lib/python3.8/ctypes/__init__.py", line 7, in <module>
    from _ctypes import Union, Structure, Array
ModuleNotFoundError: No module named '_ctypes'

Before trying it with Python 3.8.15, I also tried it with 3.11.0 with exactly the same result. Is there an easy fix here or is it just not possible to run current Electrum on the older OS?

@accumulator
Copy link
Member

/usr/local/lib/python3.8 is a strange place to have python modules in Buster. Make sure you have python installed through the debian package manager.

@flyerbear
Copy link
Author

I installed from source via the tarball downloaded from python.org. I had trouble installing with apt-get. I tried sudo apt-get install python3.8, which is what I thought the command was, and it couldn't find that package. I learned later that I needed to add the deadsnakes/ppa repository, right?

That being said, I was able to correct the above issue by installing libffi-dev with sudo apt-get install libffi-dev and then reinstalling from source again. Unfortunately, then I ran into an import ssl issue, which I am working on. If this doesn't work, I will try again with apt-get.

I'm sorry for opening this issue...I thought there might be a problem with the dependencies installation but I think this is unique to my configuration. I'm going to close the issue.

@accumulator
Copy link
Member

accumulator commented Nov 23, 2022

You can install python3, which will pull in the exact 3.x version buster currently carries (e.g. sudo apt install python3).

If this succeeds, remember to remove your custom python install , as it otherwise might interfere with the distro provided one!

@flyerbear flyerbear reopened this Dec 2, 2022
@flyerbear
Copy link
Author

I have been continuing to try to get this working and I was hoping someone might be able to tell me where the logs are stored from any errors with launching electrum.

I have properly installed all the dependencies and Python 3.8.15. However, when I try to launch electrum, I get the error, Error: at least one of ('pycryptodomex', 'cryptography') needs to be installed. But I can confirm cryptography 2.6.1 is installed. Per a suggestion from (I think) sombernight on reddit, I tried running the following lines of code (lines 72-77 of crypto.py) separately in a python interpreter and they did not generate any errors.

    from cryptography import exceptions
    from cryptography.hazmat.primitives.ciphers import Cipher as CG_Cipher
    from cryptography.hazmat.primitives.ciphers import algorithms as CG_algorithms
    from cryptography.hazmat.primitives.ciphers import modes as CG_modes
    from cryptography.hazmat.backends import default_backend as CG_default_backend
    import cryptography.hazmat.primitives.ciphers.aead as CG_aead

Then I expanded the lines to include the version check:

    import cryptography
    if versiontuple(cryptography.__version__) < versiontuple(MIN_CRYPTOGRAPHY_VERSION):
        _logger.warning(f"found module 'cryptography' but it is too old: {cryptography.__version__}<{MIN_CRYPTOGRAPHY_VERSION}")
        raise Exception()
    from cryptography import exceptions
    from cryptography.hazmat.primitives.ciphers import Cipher as CG_Cipher
    from cryptography.hazmat.primitives.ciphers import algorithms as CG_algorithms
    from cryptography.hazmat.primitives.ciphers import modes as CG_modes
    from cryptography.hazmat.backends import default_backend as CG_default_backend
    import cryptography.hazmat.primitives.ciphers.aead as CG_aead

And, after properly moving util.py and importing versiontuple, I still didn't generate any errors. But I get the error every time I try to launch electrum. Is there a log file somewhere that would hold the error messages generated from launch so I can look for some additional info?

@SomberNight
Copy link
Member

Is there a log file somewhere that would hold the error messages generated from launch so I can look for some additional info?

see https://electrum.readthedocs.io/en/latest/faq.html#how-to-enable-debug-logging
File logging is not enabled by default, and it's not easy to enable it without launching Electrum in the first place.
However, you can supply the -v flag and get logs to stderr. (e.g. electrum -v).

You might get more logs with e.g.:

diff --git a/electrum/crypto.py b/electrum/crypto.py
index 4b50d6825e..32d2be265c 100644
--- a/electrum/crypto.py
+++ b/electrum/crypto.py
@@ -58,7 +58,7 @@ try:
     from Cryptodome.Cipher import ChaCha20 as CD_ChaCha20
     from Cryptodome.Cipher import AES as CD_AES
 except:
-    pass
+    _logger.exception("")
 else:
     HAS_CRYPTODOME = True
 
@@ -76,7 +76,7 @@ try:
     from cryptography.hazmat.backends import default_backend as CG_default_backend
     import cryptography.hazmat.primitives.ciphers.aead as CG_aead
 except:
-    pass
+    _logger.exception("")
 else:
     HAS_CRYPTOGRAPHY = True

Per a suggestion from (I think) sombernight on reddit, I tried running the following lines of code (lines 72-77 of crypto.py) separately in a python interpreter and they did not generate any errors.

When testing that, have you used the same python interpreter that you are trying to run Electrum with? You might have multiple pythons installed. You can e.g. run python3 ./run_electrum to specify which python to use.

@flyerbear
Copy link
Author

I figured out that my IDE was using a different version of Python than when running electrum, as you suggested. I reflashed the card, started from scratch and used pyenv to more tightly control what version of Python I was using. It still installed cryptography to the system version of Python as opposed to the pyenv-controlled 3.8.16, but I was able to copy the module into the pyenv file structure directly.

I didn't try your logging suggestions, but I did add some print lines to crypto.py to help debug the code. After I successfully had it import cryptography, it gave me errors for several other modules, in succession as I installed each one: six, asn1crypto, _cffi_backend, and finally PyQt5. PyQt5 was showing as already installed when I tried to use apt-get to install it, so I copied pyqt5 over from the system Python installation, the same as cryptography, and continue to get module import errors. I have also tried installing it with pip.

I think I'm just going to give up and install an older version of Electrum that was current when buster was current. That should be sufficient for my use case.

@SomberNight
Copy link
Member

It still installed cryptography to the system version of Python as opposed to the pyenv-controlled 3.8.16, but I was able to copy the module into the pyenv file structure directly.
After I successfully had it import cryptography, it gave me errors for several other modules, in succession as I installed each one: six, asn1crypto, _cffi_backend,

I guess those are transitive dependencies through cryptography that are missing because you only manually copied files.
Note that you can also python3 -m pip install cryptography instead of using apt. (again, make sure to use the correct python interpreter)

and finally PyQt5. PyQt5 was showing as already installed when I tried to use apt-get to install it, so I copied pyqt5 over from the system Python installation, the same as cryptography, and continue to get module import errors. I have also tried installing it with pip.

Unfortunately pyqt5 cannot be easily pip installed in your case as PyPI only has x86_64 pre-built wheels for it (and source ofc).
The version from apt should be perfectly fine, but I take it you are using virtual envs and hence it is not visible. Note that you can hack the PYTHONPATH to make it visible from the venv, see e.g.

electrum/electrum-env

Lines 31 to 35 in 8995a3e

export PYTHONPATH="$PYTHONPATH:"\
"/usr/local/lib/python${PYTHON_VER}/site-packages:"\
"/usr/local/lib/python${PYTHON_VER}/dist-packages:"\
"/usr/lib/python3/dist-packages:"\
"/usr/lib/python${PYTHON_VER}/site-packages:"


related: #5159

@SomberNight
Copy link
Member

Anyway I guess there is not much we can do about this issue, so I will close it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants