Dhevendhiran M
Dhevendhiran M

Reputation: 1263

Python3 command crashes the mac

I was using Python 3.6 on my mac. But recently python 3.6 has not been working and it seems, it has been removed from my system. Still not sure about the reason. I'm using macOS Monterey 12.2.1

So I did brew install python

and python --version

giving me the following result, Python 2.7.18

and the command python also returns the same.

But when I type and enter python3, it crashed the system and giving the following report as log,

python3 error log

Please refer below for more information from the crash report,

    Termination Reason:    Namespace DYLD, Code 1 Library missing
Library not loaded: /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation
Referenced from: /Library/Frameworks/Python.framework/Versions/3.6/Resources/Python.app/Contents/MacOS/Python
Reason: tried: '/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation' (no such file), '/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation' (no such file)
(terminated at launch; ignore backtrace)

Application Specific Information:
Library not loaded: /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation
Referenced from: /Library/Frameworks/Python.framework/Versions/3.6/Resources/Python.app/Contents/MacOS/Python
Reason: tried: '/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation' (no such file), '/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation' (no such file)


Error Formulating Crash Report:
dyld_process_snapshot_get_shared_cache failed

Thread 0 Crashed:
0   dyld                                0x7fff6bdb20ce __abort_with_payload + 10
1   dyld                                0x7fff6bdc81cf abort_with_payload_wrapper_internal + 80
2   dyld                                0x7fff6bdc8201 abort_with_payload + 9
3   dyld                                0x7fff6bd76613 dyld4::halt(char const*) + 375
4   dyld                                0x7fff6bd7255d dyld4::prepare(dyld4::APIs&, dyld3::MachOAnalyzer const*) + 3955
5   dyld                                0x7fff6bd714b4 start + 388


Thread 0 crashed with X86 Thread State (64-bit):
  rax: 0x0000000002000209  rbx: 0x0000000000000000  rcx: 0x00007fff5bffe338  rdx: 0x00007fff5bffe7a0
  rdi: 0x0000000000000006  rsi: 0x0000000000000001  rbp: 0x00007fff5bffe380  rsp: 0x00007fff5bffe338
   r8: 0x00007fff5bffe3a0   r9: 0x0000000000000000  r10: 0x00000000000000bf  r11: 0x0000000000000246
  r12: 0x00000000000000bf  r13: 0x00007fff5bffe7a0  r14: 0x0000000000000001  r15: 0x0000000000000006
  rip: 0x00007fff6bdb20ce  rfl: 0x0000000000000246  cr2: 0x00007fff6bd78e3c
  
Logical CPU:     0
Error Code:      0x02000209 
Trap Number:     133

Based on some other workarounds, I have tried with pyenv - pyenv install 3.6.5 But it ended up with the following error,

BUILD FAILED (OS X 12.2.1 using python-build 20180424)

Inspect or clean up the working tree at /var/folders/xl/y8f6pv9103zdvp6fy9_5py1c0000gn/T/python-build.20220419170450.10396
Results logged to /var/folders/xl/y8f6pv9103zdvp6fy9_5py1c0000gn/T/python-build.20220419170450.10396.log

Last 10 log lines:
        ret = sendfile(in, out, offset, &sbytes, &sf, flags);
              ^
./Modules/posixmodule.c:10432:5: warning: code will never be executed [-Wunreachable-code]
    Py_FatalError("abort() called from Python code didn't abort!");
    ^~~~~~~~~~~~~
clang -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include   -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include   -std=c99 -Wextra -Wno-unused-result -Wno-unused-parameter -Wno-missing-field-initializers   -I. -I./Include -I/usr/local/opt/readline/include -I/usr/local/opt/readline/include -I/Users/apple/.pyenv/versions/3.6.5/openssl/include -I/Users/apple/.pyenv/versions/3.6.5/include -I/usr/local/opt/zlib/include -I/usr/local/opt/bzip2/include -I/usr/local/opt/readline/include -I/usr/local/opt/readline/include -I/Users/apple/.pyenv/versions/3.6.5/openssl/include -I/Users/apple/.pyenv/versions/3.6.5/include -I/usr/local/opt/zlib/include -I/usr/local/opt/bzip2/include  -DPy_BUILD_CORE  -c ./Modules/pwdmodule.c -o Modules/pwdmodule.o
1 warning and 1 error generated.
make: *** [Modules/posixmodule.o] Error 1
make: *** Waiting for unfinished jobs....
1 warning generated.

The available workarounds for the above error are not working and producing more complexity on finding the root cause.

It seems some python default files have been missed from my system or some other minor issues, not sure about the reason.

So the goal is to make my system's default python version should point to the python 3.6, because need to run the AWS lambda functions locally using SAM, the lambda functions are created using python 3.6 and it has been working with my system before.

Thanks for any suggestions.

Upvotes: 2

Views: 2595

Answers (1)

AKX
AKX

Reputation: 169378

So I did brew install python

At the time of writing, that will install Python 3.9 to /usr/local, e.g. /usr/local/bin/python3.9 so that doesn't help you an awful lot with Python 3.6.

and python --version giving me the following result, Python 2.7.18 and and the command python also returns the same.

Yes – the system default Python interpreter in macOS is still Python 2, and running it interactively will warn you:

WARNING: Python 2.7 is not recommended. This version is included in macOS for compatibility with legacy software. Future versions of macOS will not include Python 2.7.

Anyway, your original error looks like you now have a half-installed or otherwise defunct framework build of Python 3.6. You could try reinstalling the newest Python.org build from https://www.python.org/downloads/macos/ (3.6.8 by the looks of it).

It's also very much possible that that old version (from 2018!) is not compatible with macOS 12.2 at all (which could be why pyenv struggles too).

In any case, Python 3.6 is past its end-of-life (and according to these Lambda docs, Lambda's support for it is also ending this year), so I'd consider upgrading to a supported version, i.e. Python 3.9 (for Lambda).

If reinstalling via Python.org does not pan out, and upgrading is not an option, you might want to consider using a Docker container with the python:3.6 image.

Upvotes: 2

Related Questions