[Mobile-sig] [Python-Dev] Import Fails in setup.py On Android

Cyd Haselton chaselton at gmail.com
Mon Feb 16 23:23:37 CET 2015


More information:
After uncommenting the select module in Setup, running make clean && make && make install, then running python3, then help(), I get the following:

bld/python/Python-3.4.2 $ python3
Python 3.4.2 (default, Feb 16 2015, 12:33:03)
[GCC 4.9.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> help()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/python/lib/python3.4/_sitebuiltins.py", line 102, in __call__
    import pydoc
  File "/usr/python/lib/python3.4/pydoc.py", line 62, in <module>
    import platform
  File "/usr/python/lib/python3.4/platform.py", line 115, in <module>
    import sys, os, re, subprocess
  File "/usr/python/lib/python3.4/subprocess.py", line 352, in <module>
    import time
ImportError: dlopen failed: cannot locate symbol "PyUnicode_DecodeLocale" referenced by "time.cpython-34m.so"...

The symbol is in libpython.3.4m.so.1...and UND in time.cpython-34m.so. For some reason time isn't finding the symbol in the shared library.

I've tried copying the library to the folder where the time module resides, and to a few other locations, with the same results.  Any ideas on what I should do next?

Cyd

On February 15, 2015 5:28:45 PM CST, Cyd Haselton <chaselton at gmail.com> wrote:
>After banging my head against libfakechroot for days I've finally
>managed to fix it to work on Android. 
>
>Moving back to Python...I ran make clean && make && make install. I run
>the installed python3 binary, run help() and get the following error:
>
>ype "help", "copyright", "credits" or "license" for more information.
>>>> help()
>Traceback (most recent call last):
>  File "<stdin>", line 1, in <module>
>File "/usr/python/lib/python3.4/_sitebuiltins.py", line 102, in
>__call__
>    import pydoc
>  File "/usr/python/lib/python3.4/pydoc.py", line 62, in <module>
>    import platform
>  File "/usr/python/lib/python3.4/platform.py", line 115, in <module>
>    import sys, os, re, subprocess
>  File "/usr/python/lib/python3.4/subprocess.py", line 406, in <module>
>    import select
>ImportError: No module named 'select'
>
>
>I then attempt to import select, then ctypes, and get the following
>errors:
>>>> import select
>Traceback (most recent call last):
>  File "<stdin>", line 1, in <module>
>ImportError: No module named 'select'
>>>> import ctypes
>Traceback (most recent call last):
>  File "<stdin>", line 1, in <module>
>File "/usr/python/lib/python3.4/ctypes/__init__.py", line 22, in
><module>
>    from struct import calcsize as _calcsize
>  File "/usr/python/lib/python3.4/struct.py", line 13, in <module>
>    from _struct import *
>ImportError: dlopen failed: cannot locate symbol "PyLong_AsSize_t"
>referenced by "_struct.cpython-34m.so"...
>>>> import _struct
>Traceback (most recent call last):
>  File "<stdin>", line 1, in <module>
>ImportError: dlopen failed: cannot locate symbol "PyLong_AsSize_t"
>referenced by "_struct.cpython-34m.so"...
>>>>
>
>Googling the ImportError turns up six results...none of them related to
>a missing PyLong_AsSize_t symbol.
>
>Has anyone seen this error before?
>
>Thanks in advance.  Headed back to look at the _struct code.
>
>Cyd
>
>On February 8, 2015 6:46:02 PM CST, Cyd Haselton <chaselton at gmail.com>
>wrote:
>>Quick Update:
>>
>>I've managed to re-compile a libfakechroot that (I believe) eliminates
>>the 'undefined reference to dlopen()' issues; problems importing
>>extensions during the build process now display meaningful errors
>>instead of crashing the entire thing.
>>
>>Some imports failed because of missing symbols (i.e. _crypt, which
>>makes sense because I don't have -lcrypt on device) and some failed
>>because of linking issues (i.e _ctypes).  The majority failed to
>>import due to an undeclared variable in setup.py...which was quickly
>>fixed.
>>
>>Once the most recent build attempt is done, I'll post relevant stack
>>traces and errors, if any.
>>
>>Cyd
>>
>>On Sat, Feb 7, 2015 at 5:36 AM, Cyd Haselton <chaselton at gmail.com>
>>wrote:
>>> Hello Russ,
>>> Thanks for the update.
>>>
>>> I'm building Python 3.4.2 from sources, (using a GCC that I
>>originally
>>> ported, then upgraded on device) on an Android device in an
>>environment that
>>> simulates a Linux filesystem using fakechroot (Terminal Emulator and
>>KBOX);
>>> Python is not currently installed in this environment.
>>>
>>> I've built other utilities in this environment successfully; the key
>>is
>>> making sure that anything that requires dlopen() is built with
>shared
>>> libraries and is linked with -lc -ldl, as Android's dlopen() is not
>>in its
>>> libc but in -ldl. The shared part is due to a limitation of the
>>> libfakechroot that the KBOX environment uses; anything calling
>>dlopen()
>>> without the necessary links will cause fakechroot to terminate the
>>process
>>> and throw an undefined symbol error
>>>
>>> For the Python build I've specified -lc -ldl in the appropriate
>>> environmental variables, in Modules/Setup and in setup.py. The
>>initial
>>> python binary is built, but it fails (with the undefined ref to
>>dlopen())
>>> when importing the extension modules it has has built. I have run nm
>>on
>>> those modules and...even though -lc -ldl is on the extension build
>>command
>>> line...the dlopen() symbol is not there.
>>>
>>> Sorry for the long explanation. Let me know if there's info I've
>left
>>out.
>>>
>>>
>>>
>>> On February 6, 2015 8:10:16 PM CST, Russell Keith-Magee
>>> <russell at keith-magee.com> wrote:
>>>>
>>>> Hi Cyd,
>>>>
>>>> This list is as good a place as any for what you're describing.
>>>>
>>>> However, it's a little difficult to provide advice without stack
>>traces
>>>> and details of how you've built your Python build to start with.
>For
>>>> example, are you cross compiling? If so, the problem you've
>>described could
>>>> be caused by referencing the wrong Python instance when running
>>setup.py.
>>>>
>>>> Yours,
>>>> Russ Magee %-)
>>>>
>>>> On Fri, Feb 6, 2015 at 3:46 AM, Cyd Haselton <chaselton at gmail.com>
>>wrote:
>>>>>
>>>>> Also, if I've got the wrong list, please let me know.  Links to
>the
>>>>> correct list/lists are optional; I just want to know if this is
>the
>>>>> right place to get help so that I can keep searching if it isn't.
>>>>>
>>>>> On Thu, Feb 5, 2015 at 5:40 AM, Cyd Haselton <chaselton at gmail.com>
>>wrote:
>>>>> > Since i'm working on an Android tablet, I am forwarding the
>>original
>>>>> > message
>>>>> > I sent to python-dev instead of re-typing the entire thing.
>>>>> >
>>>>> > To summarize: I'm building in a fakechroot environment on
>Android
>>that
>>>>> > supports dynamic calls to libc only. Something in the
>>>>> > importlib._bootstrap
>>>>> > process is not linking to...or has not been linked to...the
>>necessary
>>>>> > libraries (I've checked the module...it is being linked to -lc
>>-ldl)
>>>>> > but I
>>>>> > can't figure out what...as there's not a lot in the python docs
>>on it.
>>>>> >
>>>>> > I'm currently reading through the importlib docs but any help
>>would be
>>>>> > greatly appreciated.
>>>>> >
>>>>> > ________________________________
>>>>> > From: Eric Snow <ericsnowcurrently at gmail.com>
>>>>> > Sent: February 3, 2015 12:10:54 AM CST
>>>>> > To: Cyd Haselton <chaselton at gmail.com>
>>>>> > Cc: Python-Dev <python-dev at python.org>
>>>>> > Subject: Re: [Python-Dev] Import Fails in setup.py On Android
>>>>> >
>>>>> > On Mon, Feb 2, 2015 at 12:36 PM, Cyd Haselton
>><chaselton at gmail.com>
>>>>> > wrote:
>>>>> >>
>>>>> >>  After fixing a segfault issue (many thanks Ryan) I'm back to
>>the same
>>>>> >> issue
>>>>> >>  I was having with Python 2.7.8; the newly built python throws
>>an
>>>>> >> undefined
>>>>> >>  reference to dlopen when running setup.py...specifically when
>>>>> >> importing
>>>>> >>  just-built extensions
>>>>> >>
>>>>> >>  I've managed to narrow the problem down to the following line:
>>>>> >>
>>>>> >>  importlib._bootstrap._SpecMethods(spec).load()
>>>>> >
>>>>> >
>>>>> > That call is where modules are created (and executed) via the
>>loader
>>>>> > designated for the module by the import machinery.  So a problem
>>here
>>>>> > may simply reflect a problem with the loader.  Which module is
>>being
>>>>> > imported when you run into trouble?  Is it a C-extension module?
>>>>> >
>>>>> > Also keep in mind that
>>>>> > basically everything in importlib._bootstrap is
>>>>> > frozen into your Python binary when you build Python (or should
>>be).
>>>>> > So if you are seeing any errors related to something missing or
>>broken
>>>>> > in importlib._bootstrap, it could be related to the build step
>>where
>>>>> > importlib gets frozen.
>>>>> >
>>>>> > Either way, more info (e.g. a traceback) would be great if you
>>need
>>>>> > more
>>>>> > help.
>>>>> >
>>>>> > -eric
>>>>> >
>>>>> >
>>>>> > --
>>>>> > Sent from my Android device with K-9 Mail. Please excuse my
>>brevity.
>>>>> _______________________________________________
>>>>> Mobile-sig mailing list
>>>>> Mobile-sig at python.org
>>>>> https://mail.python.org/mailman/listinfo/mobile-sig
>>>>
>>>>
>>>
>>> --
>>> Sent from my Android device with K-9 Mail. Please excuse my brevity.
>
>-- 
>Sent from my Android device with K-9 Mail. Please excuse my brevity.

-- 
Sent from my Android device with K-9 Mail. Please excuse my brevity.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/mobile-sig/attachments/20150216/7163b7d9/attachment.html>


More information about the Mobile-sig mailing list