Title: 2.x,3.x iOS static build: Fatal Python error: exceptions bootstrapping error.
Type: crash Stage:
Components: Interpreter Core, macOS Versions: Python 3.2, Python 2.7
Status: closed Resolution: works for me
Dependencies: Superseder:
Assigned To: ronaldoussoren Nosy List: amaury.forgeotdarc, ronaldoussoren, ドミトリ.ステパヌシキン
Priority: normal Keywords:

Created on 2012-05-21 05:20 by ドミトリ.ステパヌシキン, last changed 2012-05-22 15:03 by ronaldoussoren. This issue is now closed.

File name Uploaded Description Edit
pyconfig.h ドミトリ.ステパヌシキン, 2012-05-21 05:27
config.c ドミトリ.ステパヌシキン, 2012-05-21 05:27
Python-3.2.3.tar.bz2 ドミトリ.ステパヌシキン, 2012-05-21 05:47 test project ドミトリ.ステパヌシキン, 2012-05-22 06:03 Xcode 4.3.2, u'll need patch from ドミトリ.ステパヌシキン, 2012-05-22 08:16
Messages (10)
msg161244 - (view) Author: ドミトリ ステパヌシキン (ドミトリ.ステパヌシキン) Date: 2012-05-21 05:20
I trying to make minimal part of Python to work as part (static library) of my iOS application for internal scripting. I used configure under Mac OS X(10.7) and it was successful. Then I got compilable and linkable XCode project very fast.
The problem is, when I trying to use Python by 
it fails with error "Fatal Python error: exceptions bootstrapping error." inside _PyExc_Init().
I tried to debug it, but unfortunately I cant understand why it fails. May be bacause I noob in Python source, but anyway, I need to port it. Tried 2.7.3, or latest 3.x, it was the same result as above. Any solution or hint will be very helpful.

Best Regards
msg161245 - (view) Author: ドミトリ ステパヌシキン (ドミトリ.ステパヌシキン) Date: 2012-05-21 05:26
Call stack:
#0        0x300cba1c in __pthread_kill ()
#1        0x362e43ba in pthread_kill ()
#2        0x362dcbfe in abort ()
#3        0x00127d96 in Py_FatalError at /Users/mac_user/Downloads/Python-3.2.3/IOS/pythoncore/../../Python/pythonrun.c:2169
#4        0x00155328 in _PyExc_Init at /Users/mac_user/Downloads/Python-3.2.3/IOS/pythoncore/../../Objects/exceptions.c:2042
#5        0x00127ad4 in Py_InitializeEx at /Users/mac_user/Downloads/Python-3.2.3/IOS/pythoncore/../../Python/pythonrun.c:272
#6        0x0012846a in Py_Initialize at /Users/mac_user/Downloads/Python-3.2.3/IOS/pythoncore/../../Python/pythonrun.c:332
#7        0x000d6242 in testpython at /Users/mac_user/Downloads/Python-3.2.3/IOS/test/test/testmac.c:15
#8        0x000d618e in -[ViewController viewDidLoad] at /Users/mac_user/Downloads/Python-3.2.3/IOS/test/test/ViewController.m:23
#9        0x3283ff0e in -[UIViewController view] ()
#10        0x3283e2b4 in -[UIWindow addRootViewControllerViewIfPossible] ()
#11        0x3283a332 in -[UIWindow _setHidden:forced:] ()
#12        0x3283e28e in -[UIWindow _orderFrontWithoutMakingKey] ()
#13        0x3284cc60 in -[UIWindow makeKeyAndVisible] ()
#14        0x000d5ffe in -[AppDelegate application:didFinishLaunchingWithOptions:] at /Users/mac_user/Downloads/Python-3.2.3/IOS/test/test/AppDelegate.m:35
#15        0x3283e820 in -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] ()
#16        0x32838b64 in -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] ()
#17        0x3280d7d6 in -[UIApplication handleEvent:withNewEvent:] ()
#18        0x3280d214 in -[UIApplication sendEvent:] ()
#19        0x3280cc52 in _UIApplicationHandleEvent ()
#20        0x322b7e76 in PurpleEventCallback ()
#22        0x3113d83e in __CFRunLoopDoSource1 ()
msg161259 - (view) Author: ドミトリ ステパヌシキン (ドミトリ.ステパヌシキン) Date: 2012-05-21 10:41
I tried look as deep as I can. The result from 3.2.3 port: it fails in Python/getargs.c:convertsimple():line 709, error "signed integer is less than minimum". It parses some parameters, and we have an error on last, 5th parameter. I really have no idea what happens here and why, knowing that same code works just fine under Windows.
msg161270 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2012-05-21 12:32
Most of the time, embedding python in this way requires precise control over PYTHONPATH and PYTHONHOME.  Did you try to modify them?
Something like this worked for me:
I don't know whether both are needed.
msg161323 - (view) Author: ドミトリ ステパヌシキン (ドミトリ.ステパヌシキン) Date: 2012-05-22 05:21
thank You for answer. my problem was finally solved by using build script from and patch from
msg161327 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2012-05-22 05:46
The build script you mentioned seems to be for python 2.6, did you have to change anything beyond the version numbers to get it to build python 3.2 as well?
msg161328 - (view) Author: ドミトリ ステパヌシキン (ドミトリ.ステパヌシキン) Date: 2012-05-22 06:03
actually I changed all, that was needed to build Python static library for iOS device(BTW it doesn't work for simulator, I got configure errors, I can't(or have no time if u want) to resolve), but not much changes.
Want to see working script? OK, attached.
Tested on 2.6.5, and 2.7.2(2.7.x is must have for my application, so sont tested with 3.x)
msg161330 - (view) Author: ドミトリ ステパヌシキン (ドミトリ.ステパヌシキン) Date: 2012-05-22 06:34
I embedded 2.7.2 static in iOS test app, and, at least "print "something"" is worked.
Now I *sigh* need to make it compile and work on iPhone Simulator.
I'll try hard, and upload working script, if I'll can fix this mess.
msg161334 - (view) Author: ドミトリ ステパヌシキン (ドミトリ.ステパヌシキン) Date: 2012-05-22 08:16
fixed it for build BIG FAT binary. attached.
msg161361 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2012-05-22 15:03
Thanks for posting a working script. I was mostly interested in this because I'll likely need this functionality myself in the near future ;-)
Date User Action Args
2012-05-22 15:03:00ronaldoussorensetmessages: + msg161361
2012-05-22 08:16:12ドミトリ.ステパヌシキンsetfiles: +

messages: + msg161334
2012-05-22 06:34:38ドミトリ.ステパヌシキンsetmessages: + msg161330
2012-05-22 06:03:58ドミトリ.ステパヌシキンsetfiles: +

messages: + msg161328
2012-05-22 05:46:09ronaldoussorensetmessages: + msg161327
2012-05-22 05:43:04amaury.forgeotdarcsetstatus: open -> closed
resolution: works for me
2012-05-22 05:21:33ドミトリ.ステパヌシキンsetmessages: + msg161323
2012-05-21 12:32:17amaury.forgeotdarcsetnosy: + amaury.forgeotdarc
messages: + msg161270
2012-05-21 10:41:40ドミトリ.ステパヌシキンsetmessages: + msg161259
2012-05-21 05:47:42ドミトリ.ステパヌシキンsetfiles: + Python-3.2.3.tar.bz2
2012-05-21 05:27:40ドミトリ.ステパヌシキンsetfiles: + config.c
2012-05-21 05:27:19ドミトリ.ステパヌシキンsetfiles: + pyconfig.h
2012-05-21 05:26:03ドミトリ.ステパヌシキンsetmessages: + msg161245
2012-05-21 05:24:45ドミトリ.ステパヌシキンsetversions: - Python 3.1, Python 3.3, Python 3.4
2012-05-21 05:20:29ドミトリ.ステパヌシキンcreate