python-for-ios icon indicating copy to clipboard operation
python-for-ios copied to clipboard

作者你好,在IOS9.0.2中安装python,运行报错?

Open jlzsss opened this issue 9 years ago • 26 comments

报错信息如下: dyld: Library not loaded: /usr/lib/libpython2.7.dylib Referenced from: /usr/bin/python Reason: no suitable image found. Did find: /usr/lib/libpython2.7.dylib: mmap() error 22 at address=0x00242000, size=0x0002A000 segment=__DATA in Segment::map() mapping /usr/lib/libpython2.7.dylib /usr/lib/libpython2.7.dylib: mmap() error 22 at address=0x003D6000, size=0x0002A000 segment=__DATA in Segment::map() mapping /usr/lib/libpython2.7.dylib Trace/BPT trap: 5

jlzsss avatar Oct 18 '15 09:10 jlzsss

build.sh partial patch (Xcode 7.1):

diff --git a/build.sh b/build.sh
index b25c269..073bdc8 100755
--- a/build.sh
+++ b/build.sh
@@ -32,7 +32,7 @@ echo "[Script by Linus Yang]"
 echo ""

 # sdk variable
-export IOS_VERSION="5.1"
+export IOS_VERSION="9.1"
 export DEVROOT=$("xcode-select" -print-path)"/Platforms/iPhoneOS.platform/Developer"
 export SDKROOT="$DEVROOT/SDKs/iPhoneOS${IOS_VERSION}.sdk"

@@ -69,7 +69,7 @@ fi
 # download python
 echo '[Fetching Python source code]'
 if [[ ! -a Python-${PYVER}.tar.xz ]]; then
-    curl -O http://www.python.org/ftp/python/${PYVER}/Python-${PYVER}.tar.xz
+    curl -L -O http://www.python.org/ftp/python/${PYVER}/Python-${PYVER}.tar.xz
 fi

 # extract dependency library
@@ -79,20 +79,20 @@ tar zxf "${PRELIB}" -C "${PRELIBFIX}"

 # get rid of old build
 rm -rf Python-${PYVER}
-tar Jxf Python-${PYVER}.tar.xz
+/usr/bin/tar Jxf Python-${PYVER}.tar.xz
 pushd ./Python-${PYVER} > /dev/null 2>&1

 # build for native machine
 echo '[Building for host system]'
 SAVESDK="$SDKROOT"
 export SDKROOT=""
-./configure > /dev/null 2>&1
-make > /dev/null 2>&1
+./configure
+make
 mv python.exe python.exe_for_build
 mv Parser/pgen Parser/pgen_for_build
 mv build "$PRELIBLOC/build_host"
 mv pybuilddir.txt pybuilddir_host.txt
-sed -i '' 's:build/:build_host/:g' pybuilddir_host.txt
+/usr/bin/sed -i '' 's:build/:build_host/:g' pybuilddir_host.txt
 make distclean > /dev/null 2>&1
 export SDKROOT="$SAVESDK"

@@ -103,7 +103,7 @@ patch -p1 < ../patches/Python-xcompile-${PYVER}.patch
 export CPPFLAGS="-I$SDKROOT/usr/include/ -I$PRELIBLOC/usr/include"
 export CFLAGS="$CPPFLAGS -pipe -isysroot $SDKROOT"
 export CXXFLAGS="$CFLAGS"
-export LDFLAGS="-isysroot $SDKROOT -miphoneos-version-min=3.0 -L$SDKROOT/usr/lib/ -L$PRELIBLOC/usr/lib"
+export LDFLAGS="-isysroot $SDKROOT -miphoneos-version-min=3.0 -L$SDKROOT/usr/lib/ -L$PRELIBLOC/usr/lib -segalign 4000"
 export CC="$NATICC"
 export CXX="$NATICXX"
 export LD="$DEVROOT/usr/bin/ld"
@@ -111,7 +111,7 @@ export OPT="-DNDEBUG -O3 -Wall -Wstrict-prototypes"

 # build for iphone
 echo '[Cross compiling for Darwin ARM]'
-./configure --prefix=/usr --enable-ipv6 --host=arm-apple-darwin --build=x86_64-apple-darwin --enable-shared --disable-toolbox-glue --with-signal-module --with-system-ffi --without-pymalloc ac_cv_file__dev_ptmx=yes ac_cv_file__dev_ptc=no ac_cv_have_long_long_format=yes > /dev/null 2>&1
+./configure --prefix=/usr --enable-ipv6 --host=arm-apple-darwin --build=x86_64-apple-darwin --enable-shared --disable-toolbox-glue --with-signal-module --with-system-ffi --without-pymalloc ac_cv_file__dev_ptmx=yes ac_cv_file__dev_ptc=no ac_cv_have_long_long_format=yes
 make
 mv "$PRELIBLOC/build_host" .
 make install prefix="$PWD/_install/usr" > /dev/null 2>&1
@@ -124,7 +124,7 @@ chmod +x "$LDIDLOC"
 # symlink binary
 cd "${NOWDIR}/Python-${PYVER}/_install/usr/bin"
 ln -sf python${PYSHORT} python
-sed -i '' "s:${NOWDIR}/Python-${PYVER}/_install::g" python${PYSHORT}-config
+/usr/bin/sed -i '' "s:${NOWDIR}/Python-${PYVER}/_install::g" python${PYSHORT}-config
 cd "${NOWDIR}"

 # make debian package

Fails at:

[Cross compiling for Darwin ARM]
./configure --prefix=/usr --enable-ipv6 --host=arm-apple-darwin --build=x86_64-apple-darwin --enable-shared --disable-toolbox-glue --with-signal-module --with-s
ystem-ffi --without-pymalloc ac_cv_file__dev_ptmx=yes ac_cv_file__dev_ptc=no ac_cv_have_long_long_format=yes
+ ./configure --prefix=/usr --enable-ipv6 --host=arm-apple-darwin --build=x86_64-apple-darwin --enable-shared --disable-toolbox-glue --with-signal-module --with
-system-ffi --without-pymalloc ac_cv_file__dev_ptmx=yes ac_cv_file__dev_ptc=no ac_cv_have_long_long_format=yes
checking build system type... x86_64-apple-darwin
checking host system type... arm-apple-darwin
checking for python interpreter for cross build... checking for --enable-universalsdk... no
checking for --with-universal-archs... 32-bit
checking MACHDEP... darwin
checking EXTRAPLATDIR... $(PLATMACDIRS)
checking for --without-gcc... no
checking for arm-apple-darwin-gcc... /usr/bin/arm-apple-darwin9-gcc
checking whether the C compiler works... no
configure: error: in `/Users/tatsh/dev/python-for-ios/Python-2.7.6':
configure: error: C compiler cannot create executables
See `config.log' for more details

不存在/usr/bin/arm-apple-darwin9-gcc。iOS 9.1 SDK (clang)不知道该怎么。:(

Tatsh avatar Oct 31 '15 12:10 Tatsh

I was able to get it running on OS X El Capitan with Xcode 7 & the iOS 9.1 SDK.

See https://github.com/jdelman/python-for-ios and checkout branch arm64.

jdelman avatar Nov 17 '15 00:11 jdelman

Cool except https://github.com/jdelman/python-for-ios/commit/83381dc9847e5de29f697668ff6feb0ba887fe82#diff-46cb3d86e30c6dd7e235dbd05f49b19fR16 . Doesn't this make os.environ always have an empty dict? from os import environ; environ

I do not know if there is a good workaround without using Objective-C at this point. _NSGetEnviron() is not documented and environ (global char **) apparently does not work as expected on OS X and iOS.

With Objective-C, and telling the compiler to use that language for that file (-x objective-c, rename to .m maybe works too), you could call [[NSProcessInfo processInfo] environment] but you would have to convert the NSDictionary of NSStrings back to a regular char ** ('KEY=VALUE' for each).

NSDictionary *objectiveCEnv = [[NSProcessInfo processInfo] environment];
for (NSString *aKey in objectiveCEnv) {
    char *tmp = [[NSString stringWithFormat:@"%@=%@", aKey, objectiveCEnv[aKey]] UTF8String];
   // ...
}

Tatsh avatar Nov 17 '15 00:11 Tatsh

Good point, I hacked it together haphazardly & blindly without realizing the environment meant... the environment - I don't really know what I'm doing.

I fired it up after that and saw I also couldn't import math, or urllib2 (couldn't "import _socket").

Are you saying you'd replace crt_externs.h with that Obj-C code?

On Mon, Nov 16, 2015 at 7:55 PM, Andrew Udvare [email protected] wrote:

Cool except jdelman@83381dc#diff-46cb3d86e30c6dd7e235dbd05f49b19fR16 https://github.com/jdelman/python-for-ios/commit/83381dc9847e5de29f697668ff6feb0ba887fe82#diff-46cb3d86e30c6dd7e235dbd05f49b19fR16 . Doesn't this make os.environ always have an empty dict? from os import environ; environ

I do not know if there is a good workaround without using Objective-C at this point. _NSGetEnviron() is not documented and environ (global char **) apparently does not work as expected on OS X and iOS.

With Objective-C, and telling the compiler to use that language for that file (-x objective-c, rename to .m maybe works too), you could call [[NSProcessInfo processInfo] environment] but you would have to convert the NSDictionary of NSStrings back to a regular char ** ('KEY=VALUE' for each).

NSDictionary *objectiveCEnv = [[NSProcessInfo processInfo] environment];for (NSString *aKey in objectiveCEnv) { char *tmp = [[NSString stringWithFormat:@"%@=%@", aKey, objectiveCEnv[aKey]] UTF8String]; // ... }

— Reply to this email directly or view it on GitHub https://github.com/linusyang/python-for-ios/issues/3#issuecomment-157224472 .

jdelman avatar Nov 17 '15 02:11 jdelman

Nah, I think if char **environ works on iOS, otherwise it will just return NULL. But the code already checks for that. You only needed to remove the direct call to _NSGetEnviron() because it does not exist on iOS (anymore I think). Otherwise you are missing a link to libSystem (libSystem is supposed to have it).

Tatsh avatar Nov 17 '15 02:11 Tatsh

Also with regard to some modules, I do not think all the modules worked in the previous build either.

Tatsh avatar Nov 17 '15 02:11 Tatsh

@jdelman any news on this? Would love to get python working on iOS 9

teknogeek avatar Nov 23 '15 23:11 teknogeek

Mark and wait for ios9 version

formoon avatar Dec 09 '15 06:12 formoon

https://www.dropbox.com/s/qp862ppjz3rzi81/Python-2.7.8-arm64.zip?dl=0 This one seems work for me, find this link from: http://iphonedevwiki.net/index.php/Updating_extensions_for_iOS_9

Only install python it self may work, but I install all deb package. need ldid -S /usr/bin/python2.7 first else will get kill -9 error.

formoon avatar Dec 15 '15 08:12 formoon

@formoon What model iPhone are you running that on? Is it a 32-bit (iPhone 5 and earlier) or 64-bit (iPhone 5S and later) model?

jdelman avatar Dec 18 '15 22:12 jdelman

64bit iPhone6s. andrew

发自我的 iPhone

在 2015年12月19日,06:05,Josh Delman [email protected] 写道:

@formoon What model iPhone are you running that on? Is it a 32-bit (iPhone 5 and earlier) or 64-bit (iPhone 5S and later) model?

— Reply to this email directly or view it on GitHub.

formoon avatar Dec 18 '15 23:12 formoon

@formoon I had installed Python 2.7.6 for iOS (build 3),and ldid -S /usr/bin/python2.7,but I still get killed 9 error,ipad air2 (9.3.3)

YangTakeshi avatar Sep 03 '16 15:09 YangTakeshi

@formoon I had installed Python 2.7.6 for iOS (build 3),and ldid -S /usr/bin/python2.7,but I still get killed 9 error,ipad air2 (9.3.3)

I am getting the same error after the same steps on iPhone 6S 9.3.3

andrewfree avatar Sep 04 '16 20:09 andrewfree

Building fixed for 9.3 but not everything works.

https://github.com/Tatsh/python-for-ios/commit/1525f3d2e2a0a936242f6ba2b228ff111491548f

Tatsh avatar Sep 04 '16 22:09 Tatsh

@jdelman I forked your repo and can build, however seeing 'No module named select' while trying to import subprocess. Any idea?

Seeing logs:

Failed to build these modules:
_bisect            _bsddb             _codecs_cn      
_codecs_hk         _codecs_iso2022    _codecs_jp      
_codecs_kr         _codecs_tw         _collections    
_csv               _ctypes            _ctypes_test    
_curses            _curses_panel      _elementtree    
_functools         _hashlib           _heapq          
_hotshot           _io                _json           
_locale            _lsprof            _multibytecodec 
_multiprocessing   _random            _socket         
_ssl               _struct            _testcapi       
array              audioop            binascii        
cmath              cPickle            crypt           
cStringIO          datetime           dbm             
fcntl              future_builtins    grp             
itertools          math               mmap            
operator           parser             pyexpat         
readline           resource           select          
strop              syslog             termios         
time               unicodedata      

liuxuan30 avatar Sep 13 '16 09:09 liuxuan30

There is a ton of stuff to fix to make this work fully again (or usefully). Some of those are not fixable (easily) but most are. They require libraries to be present, some of which don't exist on Cydia. You really should go for modularism here and build those libraries as separate packages for Cydia and then build Python based on those. It will help many projects to have updated libraries.

Tatsh avatar Sep 13 '16 09:09 Tatsh

I was able to build a version for IOS 9 from jdelman's branch; is that going to be merged into this mainline? also, is anybody actively working these issues that @Tatsh references above?

cclamb avatar Oct 12 '16 19:10 cclamb

...also, this is a link to the DEB file I built and installed on 9.3.3 with the Pangu break:

https://drive.google.com/open?id=0B5vZIFDVHQ19d25KY2xlbUdLVzQ

Perhaps you guys could make this available as a release, with caveats?

cclamb avatar Oct 12 '16 19:10 cclamb

@cclamb if you made any improvements, please provide a patch or set of patches.

Tatsh avatar Oct 12 '16 21:10 Tatsh

No, I haven't touched the code yet, but I was able to build the arm64 branch of the repo @jdelman forked; maybe he could submit a pull request? I could not build from master on this repo, which is why I'm asking.

I'm happy to pitch in, but I don't see any specific issues in the issue tracker than need to be fixed, though I see a few things alluded to here. Is anybody actively tracking these yet?

cclamb avatar Oct 12 '16 21:10 cclamb

Well, https://github.com/jdelman/python-for-ios/commit/83381dc9847e5de29f697668ff6feb0ba887fe82 is not exactly the same as my patch. We need to merge these results. And then keep going. Also need to future-proof for iOS 10 in this effort. The code should compile for a non-jailbroken updated iOS 10 device, and still work with iOS 9.3.3, maybe 9.0.2 for those stuck behind.

Tatsh avatar Oct 12 '16 21:10 Tatsh

Ah, okay. So your patch isn't pushed. Do I just need to apply the patchfile above?

cclamb avatar Oct 12 '16 22:10 cclamb

Compare https://github.com/Tatsh/python-for-ios/commit/1525f3d2e2a0a936242f6ba2b228ff111491548f with https://github.com/jdelman/python-for-ios/commit/83381dc9847e5de29f697668ff6feb0ba887fe82 and see what's new and what's improved in @jdelman's version. He seems to have a new patch there for the environ module.

Also note full paths (like /usr/bin/sed) in mine as the Makefile is for OS X, so we force the use of BSD coreutils instead of GNU. OS X comes with BSD, not GNU. Supporting both with conditionals in the Makefile could be an option in the future.

Tatsh avatar Oct 12 '16 22:10 Tatsh

@Tatsh always get error on compile for 64 bit from your repo,

configure: error: in `/Users/masbog/GitHub/python-for-ios/Python-2.7.6':

configure: error: C compiler cannot create executables

See `config.log' for more details

and config.log said :

-----------

confdefs.h.

-----------

/* confdefs.h */ #define _GNU_SOURCE 1 #define _NETBSD_SOURCE 1 #define __BSD_VISIBLE 1 #define _BSD_TYPES 1 #define _DARWIN_C_SOURCE 1 #define _XOPEN_SOURCE 600 #define _XOPEN_SOURCE_EXTENDED 1 #define _POSIX_C_SOURCE 200112L

configure: exit 77

any suggestion for fix it? i use xCode 8.2.1 ☹️

masbog avatar Jan 31 '17 21:01 masbog

I don't get that error and the only difference now is this (master branch on my repo):

diff --git a/build.sh b/build.sh
index 7f91eca..6b3c3c2 100755
--- a/build.sh
+++ b/build.sh
@@ -32,7 +32,7 @@ echo "[Script by Linus Yang]"
 echo ""

 # sdk variable
-export IOS_VERSION="9.3"
+export IOS_VERSION="10.2"
 export DEVROOT=$("xcode-select" -print-path)"/Platforms/iPhoneOS.platform/Developer"
 export SDKROOT="$DEVROOT/SDKs/iPhoneOS${IOS_VERSION}.sdk"

Tatsh avatar Jan 31 '17 21:01 Tatsh

damn... something wrong with my env... 🤔

masbog avatar Feb 01 '17 21:02 masbog