How to Install Beem Python on Termux - Update

avatar
(Edited)

    There have been a few changes in the requirements needed to install Beem on Termux. I will be sharing those requirements in this guide. Additionally, will be submitting a pull request for these updates to be included in the official readme.

Repository:

https://github.com/holgern/beem

Termux is a free and open source terminal emulator for Android which allows for running a Linux environment on an Android device. In addition, various software can be installed through the application's package manager.

Wiki Source

    During the process of troubleshooting my new install on my Samsung Galaxy Tab Lite A7, I learned that the current Google Play release of Termux is not well-maintained. When attempting to update packages, it was discovered that there are broken links to the repositories this release points.

    This results in non-functional installs for Clang, Termux's C++ compiler, that, in turn results in failure to install the Python cryptography modules leveraged by Beem. It may be possible to install without said module; however, such is less than ideal as @holger80 recommends the module for the following reason:

Signing and Verify can be fasten (200 %) by installing cryptography (you may need to replace pip3 by pip)

    Fortunately, there is a version of Termux available that is better maintained on the f-droid app marketplace without this issue. Use the following steps:

1. Install f-droid. You may be asked to grant permissions to Install Unknown Apps. Grant the permission from whichever provider you desire to install the app i.e. file manager.

2. Install Termux via the f-droid marketplace. Again, grant the permission to Install Unknown Apps

3. Now, open the Termux application and issue the first command as follows:

pkg install clang rust python


Type 'Y' when prompted.

    Per the cryptography.io documentation, Rust is now a requirement for the following reason:

Why does cryptography require Rust?

cryptography uses OpenSSL (see: Use of OpenSSL) for its cryptographic operations. OpenSSL is the de facto standard for cryptographic libraries and provides high performance along with various certifications that may be relevant to developers. However, it is written in C and lacks memory safety. We want cryptography to be as secure as possible while retaining the advantages of OpenSSL, so we’ve chosen to rewrite non-cryptographic operations (such as ASN.1 parsing) in a high performance memory safe language: Rust.

4. Set the CARGO_BUILD_TARGET environmental variable used by rust.

    In order to prevent the following error, it is necessary to determine your rust target architecture and accordingly set the CARGO_BUILD_TARGET environmental variable.

error: Don't know the correct rust target for system type aarch64-unknown-linux-android. Please set the CARGO_BUILD_TARGET environment variable.

    After a bit of research, I found the correct procedure to resolve this issue via the following Github users bug report.

    They did take a bit of flak due to the nature of their report but, thankfully for us, that user was able to find the solution despite it. Here are the steps to set the appropriate CARGO_BUILD_TARGET:

rustc --print target-list

    This will enumerate all processor / OS architectures that may be targeted. I was able to easily deduce mine based on the build messages but that isn't necessary.

  • Do you know the processor type of your device?
  • Do you know it's operating system?

    With this information you should be able to deduce as well but, if you are having difficulty, you could just run "pip install cryptography" and then note the build messages. Example:

...
creating build/lib.linux-aarch64-3.10/cryptography
  copying src/cryptography/__about__.py -> build/lib.linux-aarch64-3.10/cryptography
  copying src/cryptography/__init__.py -> build/lib.linux-aarch64-3.10/cryptography
...

    In my case, the appropriate target was 'aarch64-linux-android' and, so then, I was able to set the environmental variable using the following command:

export CARGO_BUILD_TARGET=aarch64-linux-android

    Before attempting to install cryptography, you may want to install the wheel module. Do so with the 'pip install wheel' command. It wasn't necessary in my case but it may speed up your installation.

Congratulations! We've made it to our last couple of steps. Now, issue the following command to install cryptography.

5. Install the Python cryptography module.

pip install cryptography

6. Install Beem Python library.

Finally, we are ready to install Beem. Do so with the following command:

pip install beem

Success!

Note: All included images in this guide are self-hosted on SiaSky, a SiaCoin Skynet powered CDN provider.

Let me know if you have any questions or happen to hit a snag! Glad to help!



0
0
0.000
19 comments
avatar

In case any were wondering, we don't have to install OpenSSL because it is already installed in the f-droid version of Termux.

0
0
0.000
avatar

I'd not even thought of installing beem on Android. Could have some interesting applications. I did try putting it on a Raspberry Pi, but get errors when I import it in a script.

0
0
0.000
avatar

Interesting, would like to hear more about the process you are using. So, you're able to install been but importing a script using the python imports fails? Am I understanding correctly?

Can't say I've installed on a pi but I do have a few that I could toy around with which I just might. 😉

0
0
0.000
avatar

I used pip to install it.

Python 3.9.2 (default, Mar 12 2021, 04:06:34)
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from beem import Hive
Illegal instruction

I think I have the latest version

pi@raspberrypi:~ $ pip list|grep beem
beem 0.24.26

I did ask in the beem discord, but didn't get a response. I would think someone has it working on a Pi as they should be ideal for running a simple bot. That's what I want to do.

!PIZZA

0
0
0.000
avatar

Have you attempted import in a lesser version of Python. Suspect maybe there may be a compatibility issue.

For troubleshooting, you could also try to interactively load the module piece by piece to identify at just what point it fails.

https://github.com/holgern/beem/blob/master/beem/hive.py

You will need to take into account that some of the imports are relative so may need to tweak things slightly so the interpreter knows where to point.

Example:

Change

from .amount import Amount

to something like

from beem.amount import Amount

Then, I would feed it each function and then hope for a more descriptive error message. It does appear that there is logging defined in the module but, given it's context inside the module, I am not sure where said logs may be accessed. See below:

log = logging.getLogger(__name__)

Perhaps someone will be able to read this and give us more insight but, aside from the steps I described, not sure how I would go about troubleshooting the issue.

Good luck! 👍

0
0
0.000
avatar

I tried different parts, but always get it, so I guess it must be in the core code. Could be something the Pi can't handle.

0
0
0.000
avatar

So, you haven't been able to determine which part of the module I linked that it errors out. Think that could get us closer to the prize so to speak.

Been a while since I played with my PIs but maybe I'll give it a try. Do you recall which image or build you were using?

0
0
0.000
avatar

It seems to do it on any module. Is there any C code in beem? That would need compiling for ARM.

I used the 'Lite' image. Only used a 2GB card and it only just fit. I'll have to get a bigger one.

If people suggest things to try I can give it a go.

0
0
0.000
avatar

Believe @themarkymark dabbles in pi systems and has written a few articles about them. Not sure if he has tried to get Beem up and running but worth a mention to perhaps see if he has. 👀

My primary use case for Pi SBCs would be automating my garden watering which I have yet to undertake just yet. For Hive things, I generally use my servers but now that I can use my Android devices that is subject to change.

0
0
0.000
avatar

I don't run any servers, but a Pi could handle some simple stuff whilst not burning too many electrons. I have a bunch of them doing nothing for now.

0
0
0.000
avatar

It seems to work fine for me on a Pi 4.

image.png

0
0
0.000
avatar

I'm using a Pi Zero. Not sure how much difference in compatibility there is. I have a Pi 3 I can try.

0
0
0.000
avatar

Pi zero in theory should work but it is a very low end device

0
0
0.000
avatar

I know, but I had to try it anyway. For a simple bot it should be enough.

0
0
0.000
avatar

In theory it should be. Python isn’t the most optimized language though.

0
0
0.000