Last updated: Apr 13, 2024
Reading time·3 min
The Python error "Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)" occurs when the software you're running has attempted to access a restricted area of memory.
This may occur for multiple reasons:
gdb
package when debuggingIf you are on Linux, you can install and use the gdb
package to debug your
Python code.
If you don't already have the module installed, issue the following command.
sudo apt-get install gdb
gdb --args python your_file.py
Make sure to replace the your_file.py
placeholder with the name of your actual
script, e.g. main.py
.
Enter
until you see the (gdb)
label to the left.run
and hit Enter
.run
Here is the main.py
file I used for the example.
with open('example.txt', 'w', encoding='utf-8') as f: f.write('bobby' + '\n') f.write('hadz' + '\n') f.write('com' + '\n')
The run
command will run your Python script and should show how the error
occurred in the output.
The error is also caused when you have an outdated, broken version of a third-party module, e.g. tensorflow.
If you want to upgrade a specific package, issue the pip install
command with
the --upgrade option.
pip install tensorflow --upgrade pip3 install tensorflow --upgrade
Make sure to replace tensorflow
with the name of the package you'd like to
update to the latest version.
If that didn't help, you can try to update all packages in your environment to the latest version.
Here is a Python script you can use.
import pkg_resources from subprocess import call packages = [dist.project_name for dist in pkg_resources.working_set] call("pip install --upgrade " + ' '.join(packages), shell=True)
main.py
and run the file with python main.py
to upgrade all of the outdated packages.Here are alternative commands you can use to upgrade all outdated packages.
# 👇️ macOS or Linux pip install -U `pip list --outdated | awk 'NR>2 {print $1}'` # 👇️ Windows for /F "delims= " %i in ('pip list --outdated') do pip install -U %i
If you use a requirements.txt file, you can update it with the following command.
pip freeze > requirements.txt
Try to restart your code editor after upgrading all modules.
You might also get the error if you're trying to read from or write to a file that is opened by another program.
Make sure the file is closed by all programs (e.g. Notepad, Excel, etc) before you try to interact with it.
The error also occurs when you have a glitched virtual environment.
If you want to recreate your virtual environment, follow these steps:
requirements.txt
file.pip freeze > requirements.txt # or pip3 pip3 freeze > requirements.txt
deactivate
venv
.# For macOS and Linux rm -rf venv # For Windows rd /s /q "venv"
python -m venv venv
# For macOS and Linux source venv/bin/activate # For Windows venv\Scripts\activate.bat
requirements.txt
file.pip install -r requirements.txt
If the python -m venv venv
command doesn't work, try the following 2 commands:
python3 -m venv venv
py -m venv venv
Try to rerun your Python script from within the new virtual environment.
You might have also run into memory issues while processing your Python script.
In this case, it is best to just restart your PC and try to rerun your Python script.
You can learn more about the related topics by checking out the following tutorials: