<h3 dir="auto">Bug report</h3>
<p dir="auto">A segmentation fault happening with PySide2 5.12.1 but not with 5.11.0.<br>
This might be an upstream issue.</p>
<p dir="auto"><strong>Code for reproduction</strong></p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import sys
import faulthandler
faulthandler.enable(file=sys.stdout)

from matplotlib import rcParams
from matplotlib.backends.backend_qt5agg import FigureCanvas as Canvas
from matplotlib.figure import Figure
from PySide2.QtWidgets import QApplication, QVBoxLayout, QWidget

class MatplotlibWidget(QWidget):
    def __init__(self):
        QWidget.__init__(self)
        self.canvas = Canvas(Figure())
        vertLayout = QVBoxLayout()
        vertLayout.addWidget(self.canvas)
        self.setLayout(vertLayout)
        self.axes = self.canvas.figure.add_subplot(111)

if __name__ == &quot;__main__&quot;:
    qapp = QApplication(sys.argv)
    app = MatplotlibWidget()
    app.axes.plot(range(12), range(12))
    app.show()
    qapp.exec_()"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">sys</span>
<span class="pl-k">import</span> <span class="pl-s1">faulthandler</span>
<span class="pl-s1">faulthandler</span>.<span class="pl-en">enable</span>(<span class="pl-s1">file</span><span class="pl-c1">=</span><span class="pl-s1">sys</span>.<span class="pl-s1">stdout</span>)

<span class="pl-k">from</span> <span class="pl-s1">matplotlib</span> <span class="pl-k">import</span> <span class="pl-s1">rcParams</span>
<span class="pl-k">from</span> <span class="pl-s1">matplotlib</span>.<span class="pl-s1">backends</span>.<span class="pl-s1">backend_qt5agg</span> <span class="pl-k">import</span> <span class="pl-v">FigureCanvas</span> <span class="pl-k">as</span> <span class="pl-v">Canvas</span>
<span class="pl-k">from</span> <span class="pl-s1">matplotlib</span>.<span class="pl-s1">figure</span> <span class="pl-k">import</span> <span class="pl-v">Figure</span>
<span class="pl-k">from</span> <span class="pl-v">PySide2</span>.<span class="pl-v">QtWidgets</span> <span class="pl-k">import</span> <span class="pl-v">QApplication</span>, <span class="pl-v">QVBoxLayout</span>, <span class="pl-v">QWidget</span>

<span class="pl-k">class</span> <span class="pl-v">MatplotlibWidget</span>(<span class="pl-v">QWidget</span>):
    <span class="pl-k">def</span> <span class="pl-en">__init__</span>(<span class="pl-s1">self</span>):
        <span class="pl-v">QWidget</span>.<span class="pl-en">__init__</span>(<span class="pl-s1">self</span>)
        <span class="pl-s1">self</span>.<span class="pl-s1">canvas</span> <span class="pl-c1">=</span> <span class="pl-v">Canvas</span>(<span class="pl-v">Figure</span>())
        <span class="pl-s1">vertLayout</span> <span class="pl-c1">=</span> <span class="pl-v">QVBoxLayout</span>()
        <span class="pl-s1">vertLayout</span>.<span class="pl-en">addWidget</span>(<span class="pl-s1">self</span>.<span class="pl-s1">canvas</span>)
        <span class="pl-s1">self</span>.<span class="pl-en">setLayout</span>(<span class="pl-s1">vertLayout</span>)
        <span class="pl-s1">self</span>.<span class="pl-s1">axes</span> <span class="pl-c1">=</span> <span class="pl-s1">self</span>.<span class="pl-s1">canvas</span>.<span class="pl-s1">figure</span>.<span class="pl-en">add_subplot</span>(<span class="pl-c1">111</span>)

<span class="pl-k">if</span> <span class="pl-s1">__name__</span> <span class="pl-c1">==</span> <span class="pl-s">"__main__"</span>:
    <span class="pl-s1">qapp</span> <span class="pl-c1">=</span> <span class="pl-v">QApplication</span>(<span class="pl-s1">sys</span>.<span class="pl-s1">argv</span>)
    <span class="pl-s1">app</span> <span class="pl-c1">=</span> <span class="pl-v">MatplotlibWidget</span>()
    <span class="pl-s1">app</span>.<span class="pl-s1">axes</span>.<span class="pl-en">plot</span>(<span class="pl-en">range</span>(<span class="pl-c1">12</span>), <span class="pl-en">range</span>(<span class="pl-c1">12</span>))
    <span class="pl-s1">app</span>.<span class="pl-en">show</span>()
    <span class="pl-s1">qapp</span>.<span class="pl-en">exec_</span>()</pre></div>
<p dir="auto"><strong>Actual outcome</strong></p>
<p dir="auto">This code works fine for PySide2 5.11.0 but crashes for 5.12.1:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Fatal Python error: Segmentation fault

Current thread 0x00000001142cb5c0 (most recent call first):
  File &quot;&lt;frozen importlib._bootstrap_external&gt;&quot;, line 525 in _compile_bytecode
  File &quot;&lt;frozen importlib._bootstrap_external&gt;&quot;, line 857 in get_code
  File &quot;&lt;frozen importlib._bootstrap_external&gt;&quot;, line 724 in exec_module
  File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 677 in _load_unlocked
  File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 967 in _find_and_load_unlocked
  File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 983 in _find_and_load
  File &quot;/usr/local/lib/python3.7/site-packages/matplotlib/projections/__init__.py&quot;, line 3 in &lt;module&gt;
  File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 219 in _call_with_frames_removed
  File &quot;&lt;frozen importlib._bootstrap_external&gt;&quot;, line 728 in exec_module
  File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 677 in _load_unlocked
  File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 967 in _find_and_load_unlocked
  File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 983 in _find_and_load
  File &quot;/usr/local/lib/python3.7/site-packages/matplotlib/figure.py&quot;, line 42 in &lt;module&gt;
  File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 219 in _call_with_frames_removed
  File &quot;&lt;frozen importlib._bootstrap_external&gt;&quot;, line 728 in exec_module
  File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 677 in _load_unlocked
  File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 967 in _find_and_load_unlocked
  File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 983 in _find_and_load
  File &quot;/usr/local/lib/python3.7/site-packages/matplotlib/backends/backend_qt5.py&quot;, line 17 in &lt;module&gt;
  File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 219 in _call_with_frames_removed
  File &quot;&lt;frozen importlib._bootstrap_external&gt;&quot;, line 728 in exec_module
  File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 677 in _load_unlocked
  File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 967 in _find_and_load_unlocked
  File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 983 in _find_and_load
  File &quot;/usr/local/lib/python3.7/site-packages/matplotlib/backends/backend_qt5agg.py&quot;, line 11 in &lt;module&gt;
  File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 219 in _call_with_frames_removed
  File &quot;&lt;frozen importlib._bootstrap_external&gt;&quot;, line 728 in exec_module
  File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 677 in _load_unlocked
  File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 967 in _find_and_load_unlocked
  File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 983 in _find_and_load
  File &quot;script.py&quot;, line 6 in &lt;module&gt;
[1]    98230 segmentation fault  python3 script.py"><pre class="notranslate"><code class="notranslate">Fatal Python error: Segmentation fault

Current thread 0x00000001142cb5c0 (most recent call first):
  File "&lt;frozen importlib._bootstrap_external&gt;", line 525 in _compile_bytecode
  File "&lt;frozen importlib._bootstrap_external&gt;", line 857 in get_code
  File "&lt;frozen importlib._bootstrap_external&gt;", line 724 in exec_module
  File "&lt;frozen importlib._bootstrap&gt;", line 677 in _load_unlocked
  File "&lt;frozen importlib._bootstrap&gt;", line 967 in _find_and_load_unlocked
  File "&lt;frozen importlib._bootstrap&gt;", line 983 in _find_and_load
  File "/usr/local/lib/python3.7/site-packages/matplotlib/projections/__init__.py", line 3 in &lt;module&gt;
  File "&lt;frozen importlib._bootstrap&gt;", line 219 in _call_with_frames_removed
  File "&lt;frozen importlib._bootstrap_external&gt;", line 728 in exec_module
  File "&lt;frozen importlib._bootstrap&gt;", line 677 in _load_unlocked
  File "&lt;frozen importlib._bootstrap&gt;", line 967 in _find_and_load_unlocked
  File "&lt;frozen importlib._bootstrap&gt;", line 983 in _find_and_load
  File "/usr/local/lib/python3.7/site-packages/matplotlib/figure.py", line 42 in &lt;module&gt;
  File "&lt;frozen importlib._bootstrap&gt;", line 219 in _call_with_frames_removed
  File "&lt;frozen importlib._bootstrap_external&gt;", line 728 in exec_module
  File "&lt;frozen importlib._bootstrap&gt;", line 677 in _load_unlocked
  File "&lt;frozen importlib._bootstrap&gt;", line 967 in _find_and_load_unlocked
  File "&lt;frozen importlib._bootstrap&gt;", line 983 in _find_and_load
  File "/usr/local/lib/python3.7/site-packages/matplotlib/backends/backend_qt5.py", line 17 in &lt;module&gt;
  File "&lt;frozen importlib._bootstrap&gt;", line 219 in _call_with_frames_removed
  File "&lt;frozen importlib._bootstrap_external&gt;", line 728 in exec_module
  File "&lt;frozen importlib._bootstrap&gt;", line 677 in _load_unlocked
  File "&lt;frozen importlib._bootstrap&gt;", line 967 in _find_and_load_unlocked
  File "&lt;frozen importlib._bootstrap&gt;", line 983 in _find_and_load
  File "/usr/local/lib/python3.7/site-packages/matplotlib/backends/backend_qt5agg.py", line 11 in &lt;module&gt;
  File "&lt;frozen importlib._bootstrap&gt;", line 219 in _call_with_frames_removed
  File "&lt;frozen importlib._bootstrap_external&gt;", line 728 in exec_module
  File "&lt;frozen importlib._bootstrap&gt;", line 677 in _load_unlocked
  File "&lt;frozen importlib._bootstrap&gt;", line 967 in _find_and_load_unlocked
  File "&lt;frozen importlib._bootstrap&gt;", line 983 in _find_and_load
  File "script.py", line 6 in &lt;module&gt;
[1]    98230 segmentation fault  python3 script.py
</code></pre></div>
<p dir="auto"><strong>Matplotlib version</strong></p>
<ul dir="auto">
<li>Operating system: macOS X 10.14.3</li>
<li>Matplotlib version: 3.0.2</li>
<li>Python version:  3.7.2</li>
</ul>
<h3 dir="auto">Bug report</h3>
<p dir="auto"><strong>Bug summary</strong></p>
<p dir="auto">Importing matplotlib after PySide2 is imported causes crash occasionally. When the order of imports is reversed, the occasional crash goes away. I'm not sure whether this is PySide2's problem or Matplotlib's. I've also reported this bug on <a href="https://bugreports.qt.io/browse/PYSIDE-937" rel="nofollow">Qt Bug Tracker</a>.</p>
<p dir="auto"><strong>Code for reproduction</strong></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="from PySide2.QtCore import *
from PySide2.QtGui import *
from PySide2.QtWidgets import *

print('pyside')

import matplotlib.pyplot

print('matplotlib')"><pre class="notranslate"><code class="notranslate">from PySide2.QtCore import *
from PySide2.QtGui import *
from PySide2.QtWidgets import *

print('pyside')

import matplotlib.pyplot

print('matplotlib')
</code></pre></div>
<p dir="auto"><strong>Actual outcome</strong></p>
<p dir="auto">No specific error message, I only got this:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Process finished with exit code -1073741819 (0xC0000005)"><pre class="notranslate"><code class="notranslate">Process finished with exit code -1073741819 (0xC0000005)
</code></pre></div>
<p dir="auto"><strong>Matplotlib version</strong></p>
<ul dir="auto">
<li>Operating system: Windows 10 64-bit</li>
<li>Matplotlib version: 3.0.2</li>
<li>Matplotlib backend (<code class="notranslate">print(matplotlib.get_backend())</code>): TkAgg</li>
<li>Python version: 3.7.2 64-bit</li>
<li>Other libraries: PySide2/shiboken2: 5.12.1</li>
</ul>
<p dir="auto">Matplotlib, PySide2/shiboken2 were all installed via pip.</p>