termux-packages icon indicating copy to clipboard operation
termux-packages copied to clipboard

[Bug]: PyTorch doesn't work

Open marbetschar opened this issue 1 year ago • 10 comments

Problem description

When I execute pkg install python-torch and then in my python file try to import torch, I get the following error message:

ImportError: dlopen failed: cannot locate symbol "_ZN4absl12lts_202308021hash_internal15MixingHashState5kSeedE" referenced by "/data/data/com.termux/files/usr/lib/python3.11/site-packages/torch/lib/libtorch_python.so"...

Steps to reproduce the behavior.

On a freshly installed Termux, run pkg install python-torch. Then try to import torch from a python file and execute this python file.

What is the expected behavior?

PyTorch should simply work when installed using Termux packages - in fact, I would expect each python-* package to work out of the box when installed from official Termux repository.

I got similar issues after installing jupyter-lab and trying to start it. The pyzmq dependency throws a very similar exception:

ImportError: dlopen failed: cannot locate symbol "PyExc_ImportError" referenced by "/data/data/com.termux/files/usr/lib/python3.11/site-packages/zmq/backend/cython/_zmq.cpython-311.so"...

The solution there was to build pyzmq with the -lpython3.11 flag:

pip uninstall pyzmq
LDFLAGS="-lm -lpython3.11" pip install --no-cache pyzmq

And I've also noticed quite a few other packages seem to have the very same issue - for example numpy and pandas: https://github.com/termux/termux-app/issues/3814

I understand that maybe not every package installed via pip works out of the box on Termux. However, If I install packages from Termux repository I would expect them to work. As of today, the usage of python3.11 in Termux seems to be broken.

System information

  • Termux application version: 0.118.1
  • Android OS version: 12
  • Device model: Boox Note Air

marbetschar avatar Aug 19 '24 12:08 marbetschar

Did you update all the packages? Could you provide the version numbers of python-torch and abseil-cpp packages using apt info command?

Biswa96 avatar Aug 19 '24 13:08 Biswa96

I ran pkg upgrade, yes.

~ pkg info python-torch
Package: python-torch
Version: 2.1.2-1
Maintainer: @termux
Installed-Size: 254 MB
Depends: ffmpeg, libc++, libopenblas, libprotobuf, libzmq, opencv, python, python-numy, python-pip, fmt
...

~ pkg info abseil-cpp
Package: abseil-cpp
Version: 20240116.2
Maintainer: @termux
Installed-Size: 8663 kB
Depends: libc++
Conflicts: libgrpc (<< 1.52.0-1)
...

marbetschar avatar Aug 19 '24 13:08 marbetschar

Latest python-torch version is 2.1.2-4 as of writing this comment. Please try to change the package download mirror using termux-change-repo command. The mirror that you are using may not have latest packages.

Biswa96 avatar Aug 19 '24 13:08 Biswa96

I just gave it a test run and tried multiple mirror groups w/o any success. Switched then to Single mirror and chose packages.termux.dev - which does not provide a newer python-torch version either. It shows python-torch/stable,now 2.1.2-1 aarch64 only.

Seems like there is no newer version available of python-torch for aarch64.

marbetschar avatar Aug 19 '24 13:08 marbetschar

python-torch was moved to x11 repository. You have to install x11-repo package to get latest python-torch version.

Though I am not sure why the main repo still has the older python-torch version. It should be removed after that x11 repo migration.

Biswa96 avatar Aug 19 '24 13:08 Biswa96

Installed x11-rep and I'm now able to see python/torch 2.1.2-4. However, it still doesn't want to work:

pkg uninstall python-torch
apt autoremove
pkg update
pkg install python-torch

Then tried to run the following python file:

# test.py
import torch

print("Hello Torch!")

By running: python test.py - and I get the following output:

~ python test.py
WARNING: All log messages before absl::InitializeLog() is called are written to STDERR
F0000 00:00:1724076654.159573    28995 common.cc:63] This program was compiled against version 3.0.0 of
Protocol Buffer runtime library, which is not compatible with the installed version (4.25.1). Contact the program
author for an update. If you compiled the program yourself, make sure that your headers are from the same
version of Protocol Buffers as your link-time library.   (Version verification failed in "out/soong/.intermediates/
frameworks/base/libs/hwui/libhwui/android_arm64_armv8-a_core_static/gen/proto/frameworks/base/libs/hwui/
protos/graphicsstats.pb.cc".)
*** Check failure stack trace: **
Aborted

marbetschar avatar Aug 19 '24 14:08 marbetschar

Probably we should rebuild the python-torch package.

twaik avatar Aug 19 '24 15:08 twaik

It seems that python-torch hasn't been deleted from main-repo.

Ping: @Grimler91

licy183 avatar Aug 20 '24 12:08 licy183

It has been removed from main repo some hours ago.

Biswa96 avatar Aug 20 '24 12:08 Biswa96

Probably we should rebuild the python-torch package.

Anything I can help with to get the rebuild done? And/or can I provide additional information to find the root cause of the issue?

marbetschar avatar Aug 21 '24 05:08 marbetschar

I just noticed there is a new python-torch version 2.1.2-5 available - and after updating to this, the above mentioned issue is gone. Seems pytorch works now. Thank you very much!

marbetschar avatar Sep 02 '24 19:09 marbetschar