Repository: spyder-ide/spyder

Issue:
Spyder crashes with segmentation fault on startup in Anaconda 4.5.0
**DEVELOPER NOTE**: ***This error is now fixed in Spyder >= 3.3.0. To resolve it, please update to the current version with ``conda update spyder`` from the Anaconda Prompt/Terminal/command line**, which also fixes other bugs and adds new features, enhancement and usability/documentation improvements. Thanks!*

Hi,
after updating Spyder on Anaconda it crashes on startup. The splash screen shows up before terminating with a segmentation fault. It can be reproduced in a minimal Anaconda environment with:
  
    # Create minimal environment:
    ~$ conda --version
    conda 4.5.0
    ~$ conda create --name tst
    ~$ conda activate tst
    ~$ conda install spyder
    ~$ rm -rf ~/.config/spyder-py3
    ~$ SPYDER_DEBUG="3" spyder --reset
    *** Reset Spyder settings to defaults ***
    removing: /home/brunn/.config/spyder-py3/spyder.ini
    removing: /home/brunn/.config/spyder-py3/langconfig

    # Run spyder:
    ~$ SPYDER_DEBUG="3" spyder
    Start of MainWindow constructor
    End of MainWindow constructor
    *** Start of MainWindow setup ***
      ..core actions
      ..toolbars
      ..tools
      ..sift?
      ..plugin: internal console
        ..internal console: initializing
      ..plugin: working directory
    Loading help...
    Loading outline explorer...
    Loading editor...
    Introspection Plugin Loaded: rope
    Introspection Plugin Loaded: jedi
    Introspection Plugin Loaded: fallback
    setfocusto: <spyder.widgets.sourcecode.codeeditor.CodeEditor object at 0x7f99901c3948>
    current_changed: 0 <spyder.widgets.sourcecode.codeeditor.CodeEditor object at 0x7f99901c3948> 140297524492616
    Added thread <spyder.widgets.editor.AnalysisThread object at 0x7f9990155ee8> to queue
    Added thread <spyder.widgets.editor.AnalysisThread object at 0x7f9990155f78> to queue
      ..widgets
    Loading file explorer...
    Loading history plugin...
    Loading online help...
    Loading project explorer...
    Updating queue:
        started: 0
        pending: 2
    ===>starting: <spyder.widgets.editor.AnalysisThread object at 0x7f9990155ee8>
    Updating queue:
        started: 1
        pending: 1
    ===>starting: <spyder.widgets.editor.AnalysisThread object at 0x7f9990155f78>
    Loading namespace browser...
    Updating queue:
        started: 0
        pending: 0
    Updating queue:
        started: 0
        pending: 0
    Loading IPython console...
    Setting up main window...
    Setting up window...
    *** End of MainWindow setup ***
    Speicherzugriffsfehler (means: segmentation fault)

I'm not quite sure how to continue debugging. Investigating the core dump did not yield in any results.
I'm using Debian unstable. The conda package info returns:

    spyder 3.2.8 py36_0
    -------------------
    file name   : spyder-3.2.8-py36_0.tar.bz2
    name        : spyder
    version     : 3.2.8
    build string: py36_0
    build number: 0
    channel     : https://repo.anaconda.com/pkgs/main/linux-64
    size        : 2.6 MB
    arch        : None
    constrains  : ()
    license     : MIT
    md5         : 9ad003181d3ce2134a6f024b86a2cdab
    platform    : None
    subdir      : linux-64
    timestamp   : 1521092348360
    url         : https://repo.anaconda.com/pkgs/main/linux-64/spyder-3.2.8-py36_0.tar.bz2
    dependencies:
        chardet >=2.0
        cloudpickle
        jedi >=0.9
        nbconvert
        numpydoc
        pickleshare
        psutil
        pycodestyle
        pyflakes
        pygments >=2.0
        pylint
        pyqt
        python >=3.6,<3.7.0a0
        pyzmq
        qtawesome >=0.4.1
        qtconsole >=4.2
        qtpy >=1.2.0
        rope >=0.9.4
        sphinx


Discussion:
What are your Qt and PyQt versions?
I have the following versions installed:
   
    pyqt                      5.9.2            py36h751905a_0
    qt                        5.9.5                h7e424d6_0

The file [conda_packages.txt](https://github.com/spyder-ide/spyder/files/1918490/conda_packages.txt) contains the output of the command``conda list``.





I had the same problem (after pyqt updates Spyder crashed on startup or when I tried to resize windows). Downgrading pyqt to 5.6.0 solved the issue for me.
@ccordoba12 After installing Spyder 3.2.8 into a fresh environment on my clean test Win 10 machine with Qt/PyQt 5.9, I also got a crash on launch, while it worked just fine in a 5.6 environment on the same machine.`If you want me to do more specific testing, I can do so.
This is really bad! I thought things were working fine for PyQt 5.9 on Windows.

@CAM-Gerlach, could you post the output of `conda list` in your environment? Thanks!
@ccordoba12 Actually, good news and bad news. When I created another new environment on my test machine with Spyder and Qt 5.9, everything worked just fine. It seems the one non-Spyder additional package I'd installed in that env, the pandas soft-dependency ``feather-format`` to power the pandas ``read_feather`` and ``to_feather`` functions, downgraded qt/pyqt to 5.6.2/5.6 which completely broke Spyder to the point it would crash almost instantly on launch to a "Python has stopped working" before even printing the first debug message. Ironically, upgrading back to 5.9.4/5.9.2 got Spyder working again. However, what I have not tried is upgrading an existing env with Spyder, etc. installed from Qt/PyQt 5.6 to 5.9...if you think that would help, I can.
Attached is a [backtrace](https://github.com/spyder-ide/spyder/files/1922920/backtrace.txt) generated with:

    $ gdb /home/brunn/anaconda3/envs/tst/bin/python
    ...
    (gdb) run
    Starting program: /home/brunn/anaconda3/envs/tst/bin/python
    [Thread debugging using libthread_db enabled]
    Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1". 
    Python 3.6.5 |Anaconda, Inc.| (default, Mar 29 2018, 18:21:58) 
    ...
    >>> from spyder.app.start import main
    >>> main()
    ...
    Thread 1 "ZMQbg/5" received signal SIGSEGV, Segmentation fault.
    0x0000000000000000 in ?? ()
    (gdb) bt





Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -291,10 +291,7 @@ def run(self):
     'numpydoc',
     # Packages for pyqt5 are only available in
     # Python 3
-    'pyqt5<5.10;python_version>="3"',
-    # This is only needed for our wheels on Linux.
-    # See issue #3332
-    'pyopengl;platform_system=="Linux"'
+    'pyqt5<5.10;python_version>="3"'
 ]
 
 extras_require = {
diff --git a/spyder/app/start.py b/spyder/app/start.py
--- a/spyder/app/start.py
+++ b/spyder/app/start.py
@@ -1,6 +1,7 @@
 # -*- coding: utf-8 -*-
 
 # Std imports
+import ctypes
 import os
 import os.path as osp
 import random
@@ -12,10 +13,10 @@
 # See issue 5324
 import zmq
 
-# This import is needed to fix errors with OpenGL when installed using pip
-# See issue 3332
+# Load GL library to prevent segmentation faults on some Linux systems
+# See issues 3226 and 3332
 try:
-    from OpenGL import GL
+    ctypes.CDLL("libGL.so.1", mode=ctypes.RTLD_GLOBAL)
 except:
     pass
 


Test patch: