Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)

avatar
Borislav Hadzhiev

Last updated: Apr 13, 2024
3 min

banner

# Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)

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:

  1. Having a bug in your Python script or a bug in the code of a third-party module that you are loading.
  2. Having an outdated, broken version of a module that breaks your code.
  3. Trying to interact (read/write) with a file that is opened by another application.
  4. Running into memory issues while processing your Python script.
  5. Having a glitched virtual environment.

# Using the gdb package when debugging

If 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.

shell
sudo apt-get install gdb

install gdb module

  1. Open your terminal in your project's root directory, right next to your entry file and run the following command.
main.py
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.

  1. Press Enter until you see the (gdb) label to the left.
  2. Type run and hit Enter.
shell
run

type run and hit enter

Here is the main.py file I used for the example.

main.py
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.

# Having an outdated, broken version of a third-party module

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.

shell
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.

main.py
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)
You can store the script in a Python file, e.g. 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.

shell
# 👇️ 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.

shell
pip freeze > requirements.txt

Try to restart your code editor after upgrading all modules.

# Trying to interact (read/write) with a file that is opened by another application

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.

# Having a glitched virtual environment

The error also occurs when you have a glitched virtual environment.

If you want to recreate your virtual environment, follow these steps:

  1. Optionally update your requirements.txt file.
shell
pip freeze > requirements.txt # or pip3 pip3 freeze > requirements.txt
  1. Deactivate your virtual environment.
shell
deactivate
  1. Remove the old virtual environment. The example assumes that it is named venv.
shell
# For macOS and Linux rm -rf venv # For Windows rd /s /q "venv"
  1. Specify the correct Python version when creating your new virtual environment.
shell
python -m venv venv
  1. Activate your new virtual environment.
shell
# For macOS and Linux source venv/bin/activate # For Windows venv\Scripts\activate.bat
  1. Optionally, install the modules in your requirements.txt file.
shell
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.

# Running into memory issues while processing your Python script

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.

# Additional Resources

You can learn more about the related topics by checking out the following tutorials:

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.