I faced this same issue in the M1 Macbook pro and fixed it by doing the following
Open ~/.zshrc file (Create a new one if not present already)
Add the following line
alias python3="/usr/bin/python3"
Make sure you are able to access python3 from the above location by running
/usr/bin/python3
This should invoke Python3 for you or check for the correct path in /usr/bin and update the above line accordingly. You can do the same for other versions of Python also accordingly.
I faced this same issue in the M1 Macbook pro and fixed it by doing the following
Open ~/.zshrc file (Create a new one if not present already)
Add the following line
alias python3="/usr/bin/python3"
Make sure you are able to access python3 from the above location by running
/usr/bin/python3
This should invoke Python3 for you or check for the correct path in /usr/bin and update the above line accordingly. You can do the same for other versions of Python also accordingly.
For others who might have the same root cause: Mine had nothing to do with my Python installation, it was caused by a bad merge in Pandas (accidently creating a dataframe with 22 Billion rows, it was trying to allocate 33GB of memory).
When I run my python program in zsh using python3 Mosesh.py I get the message zsh: killed python3 Mosesh.py after a few seconds. All the program is doing at the moment is creating a list of data to work with but at most that should be about 14kB so being out of ram doesn’t seem to be the issue as most of my googling has suggested. I’ve also noticed the issue persists in other shells such as bash. Any ideas what the issue is or how to fix it? Thanks.
First, zsh (and as such all other shells) isn't killing python, it's only reporting that is has been killed.
The message 'killed' is a definitive info that the child process (python3 here) has received the uncatchable SIGKILL (9) signal. Unless there's user code that sends itself that signal, it would need a bit of debugging to determine the cause. You could use strace python3 ... to get an idea of what the program was doing at the time. Sometimes, the kernel kills a process, it would report that in the kernel messages available with dmesg.
Show us the script header and summarize what the script does, and whether the script runs as user or root.
I’ve also noticed the issue persists in other shells such as bash.
Do you mean same Python script in a different shell environment?
I suspect the Python script is overflowing the stack or some other programming no-no, thereby precipitating its own termination.
Also, the Python script should have a header that obviates the need to explicitly call the script as an argument to Python 3. A header like this:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# your program here
dmesg printed 'Unable to obtain kernel buffer: Operation not permitted'.
Trying to run a k-NN model on unseen data and getting this error, code runs fine with a smaller sample just when it came to the entire dataset it got this error.