beeware / Python-Apple-support

A meta-package for building a version of Python that can be embedded into a macOS, iOS, tvOS or watchOS project.
MIT License
1.11k stars 160 forks source link

iOS running crash #110

Closed ghost closed 3 years ago

ghost commented 3 years ago

Initializing Python runtime Fatal Python error: Py_Initialize: can't initialize sys sys.excepthook is missing object : ValueError('character U+6972702f is not in range [U+0000; U+10ffff]',) type : ValueError refcount: 1 address : 0x28123c5b8 lost sys.stderr

freakboy3742 commented 3 years ago

It looks like you've generated a ValueError in your code, but you haven't initialised the python runtime to handle that error. It's not at all clear why this is being reported as an error in the Python Apple Runtime, as you haven't provided any detail about what you have done to generate this error.

Closing this ticket as there is insufficient detail to provide any meaningful response.

ghost commented 3 years ago

NSString tmp_path; NSString python_home; wchar_t *wpython_home;

   NSString * resourcePath = [[NSBundle mainBundle] resourcePath];

   // Special environment to prefer .pyo; also, don't write bytecode
   // because the process will not have write permissions on the device.
   putenv("PYTHONOPTIMIZE=");
   putenv("PYTHONDONTWRITEBYTECODE=1");

   python_home = [NSString stringWithFormat:@"%@/Python.framework/Resources", resourcePath, nil];
   NSLog(@"PythonHome is: %@", python_home);
   wpython_home = [python_home UTF8String];
   Py_SetPythonHome(wpython_home);
   // iOS provides a specific directory for temp files.
   tmp_path = [NSString stringWithFormat:@"TMP=%@/tmp", resourcePath, nil];
   putenv((char *)[tmp_path UTF8String]);

   NSLog(@"Initializing Python runtime");
   Py_Initialize();

this is my code

ghost commented 3 years ago

i don't run same code ,only invoke Py_Initialize

cxymq commented 3 years ago

Python.framework

image What I have downloaded is not a framework

freakboy3742 commented 3 years ago

@cxymq Yes... and? Where were you promised Python-support-package was packaged as a framework?

GuFangRen commented 3 years ago

@freakboy3742 I have the same problem with @cxymq , i cant just copy the resources folder into bundle so how can i config pythonhomepath?

freakboy3742 commented 3 years ago

@GuFangRen If you want to see an example of this package being used, take a look at Briefcase. This support package primarily exists as a utility to be used by briefcase, which will generate a functioning Xcode project that embeds the Python interpreter.