yan12125 / python3-android

Python 3 cross-compilation tools for Android.
BSD Zero Clause License
91 stars 33 forks source link

Non pure-python libraries? #9

Open springishere opened 6 years ago

springishere commented 6 years ago

would like to know what's the step to port numpy as well?

yan12125 commented 6 years ago

This may be worth a try:

_PYTHON_SYSCONFIGDATA_NAME=_sysconfigdata_m_linux_aarch64-linux-android PYTHONHOME=$HOME/Projects/python3-android/build/target/python/usr python3.7 setup.py build_ext

Change architecture names and paths to fit your needs.

For more information, see https://bugs.python.org/issue28833

springishere commented 6 years ago

thanks! I wonder why the other packages (like the ncurses, openssl, readline, etc.) are not so complicated as the numpy, are they not "third-party extension modules"? Sorry I am new to this, looks like cross compiling numpy is kind of complicated.

springishere commented 6 years ago

Tried this: _PYTHON_SYSCONFIGDATA_NAME=_sysconfigdata_m_linux_aarch64-linux-android PYTHONHOME=~/python.armv8/python3-android.GRRedWings/build/15c-22-aarch64-linux-android-clang python3.5 setup.py build_ext

Got error: File "setup.py", line 386, in setup_package() File "setup.py", line 363, in setup_package from setuptools import setup ImportError: No module named 'setuptools' make: *** [numpy-1.11.0] Error 1

I can build python and other modules (like readline) without problem. The PYTHONHOME is set to the output of cross compiled python output, right?

springishere commented 6 years ago

wondering if I need to cross compile the setuptools?

yan12125 commented 6 years ago

Gosh, you hit another Python-related bug (#3): pip & setuptools doesn't work well with cross-builds. I may be able to fix them in this repo.

The PYTHONHOME is set to the output of cross compiled python output, right?

Yep. Most likely you'll get an error like "unable to import 'encodings'" when PYTHONHOME is wrong.

Another reason for this error may be that _PYTHON_SYSCONFIGDATA_NAME requires 3.6 or above.

I wonder why the other packages (like the ncurses, openssl, readline, etc.) are not so complicated as the numpy, are they not "third-party extension modules"?

You got it. Third-party extensions depend on Python's build system distutils, which does not support cross-builds well. On the other hand, ncurses, openssl, readline are excellent in supporting cross-builds.

springishere commented 6 years ago

Looks like things get more complicated. I wonder if you can take a look at numpy? If you can get this working on 3.7 (e.g. this git) that would be great...

springishere commented 6 years ago

I installed setuptools package on my ubuntu (16.04) host, added PYTHONPATH=/usr/lib/python3/dist-packages:$PYTHONPATH, so whole command is this: _PYTHON_SYSCONFIGDATA_NAME=_sysconfigdata_m_linux_aarch64-linux-android PYTHONHOME=~/python.armv8/python3-android.GRRedWings/build/15c-22-aarch64-linux-android-clang PYTHONPATH=/usr/lib/python3/dist-packages:$PYTHONPATH python3.5 setup.py build_ext

I got this error: Running from numpy source directory. Traceback (most recent call last): File "setup.py", line 386, in setup_package() File "setup.py", line 363, in setup_package from setuptools import setup File "/usr/lib/python3/dist-packages/setuptools/init.py", line 14, in from setuptools.extension import Extension File "/usr/lib/python3/dist-packages/setuptools/extension.py", line 10, in from .dist import _get_unpatched File "/usr/lib/python3/dist-packages/setuptools/dist.py", line 21, in from setuptools import windows_support File "/usr/lib/python3/dist-packages/setuptools/windows_support.py", line 2, in import ctypes File "/home/local/ANT/fengy/python.armv8/python3-android.GRRedWings/build/15c-22-aarch64-linux-android-clang/lib/python3.5/ctypes/init.py", line 7, in from _ctypes import Union, Structure, Array ImportError: No module named '_ctypes'

All the _ctypes.so that I found in the whole system are under python2.7, for example: ~/python.armv8/python3-android.GRRedWings/sdk/android-ndk-r15c/prebuilt/linux-x86_64/lib/python2.7/lib-dynload/_ctypes.so ~/python.armv8/python3-android.GRRedWings/build-tools/15c-22-aarch64-linux-android-clang/lib/python2.7/lib-dynload/_ctypes.so

yan12125 commented 6 years ago

Well, setuptools and pip shouldn't import ctypes (or any built-in extension modules) unconditionally... https://bugs.python.org/issue31652

This looks like a long term project. I don't think I can finish it in a few weeks.

All the _ctypes.so that I found in the whole system are under python2.7, for example:

Actually it tried to load the ARM version of _ctypes and failed.

springishere commented 6 years ago

I was expecting days, not weeks, looks like I underestimated the numpy :(

yan12125 commented 6 years ago

That's not numpy's problem, but the whole Python's. Its cross-builds support is never in a good shape.

yan12125 commented 4 years ago

As a side note, building modules for Android is also discussed in https://bugs.python.org/issue28833.

canewsin commented 4 years ago

i had already seen this issue but didn't tried it i will try it