Repository: spyder-ide/spyder

Issue:
IPython Console does not start if `debugpy` is not available (6.0 alpha4)
## Description

### What steps will reproduce the problem?

<!--- You can use Markdown here --->

Start freshly installed Spyder 6 (from Fedora repo). It says connecting to kernel briefly and then displays:

```
[SpyderKernelApp] WARNING | debugpy_stream undefined, debugging will not be enabled
```

I ran Spyder 6.0.0a1 with `--debug-info verbose --debug-output file`, which did not actually store any debug log in `spyder-debug.log`. I captured the console output anyway, but didn't notice any abvious issues. The referenced `debugpy_stream` var appears to be from `ipykernel`. However the same version of `ipykernel` works fine with Spyder 5.

It has been reported that the same issue appears to be present in 6.0.0a4.



## Versions

* Spyder version: 6.0.0a1  (pip)
* Python version: 3.12.2 64-bit
* Qt version: 5.15.12
* PyQt5 version: 5.15.10
* Operating System: Linux-6.8.0-0.rc6.49.fc40.x86_64-x86_64-with-glibc2.39

### Dependencies

```
# Mandatory:
atomicwrites >=1.2.0                                                        :  1.4.1 (OK)
chardet >=2.0.0                                                             :  5.2.0 (OK)
cloudpickle >=0.5.0                                                         :  3.0.0 (OK)
cookiecutter >=1.6.0                                                        :  2.5.0 (OK)
diff_match_patch >=20181111                                                 :  20230430 (OK)
intervaltree >=3.0.2                                                        :  3.1.0 (OK)
IPython >=7.31.1,<9.0.0,!=8.8.0,!=8.9.0,!=8.10.0,!=8.11.0,!=8.12.0,!=8.12.1 :  8.21.0 (OK)
jedi >=0.17.2,<0.20.0                                                       :  0.19.1 (OK)
jellyfish >=0.7                                                             :  0.9.0 (OK)
jsonschema >=3.2.0                                                          :  4.19.1 (OK)
keyring >=17.0.0                                                            :  24.3.1 (OK)
nbconvert >=4.0                                                             :  7.16.0 (OK)
numpydoc >=0.6.0                                                            :  1.6.0 (OK)
parso >=0.7.0,<0.9.0                                                        :  0.8.3 (OK)
pexpect >=4.4.0                                                             :  4.9.0 (OK)
pickleshare >=0.4                                                           :  0.7.5 (OK)
psutil >=5.3                                                                :  5.9.8 (OK)
pygments >=2.0                                                              :  2.17.2 (OK)
pylint >=2.5.0,<3.0                                                         :  3.1.0 (NOK)
pylint_venv >=3.0.2                                                         :  3.0.2 (OK)
pyls_spyder >=0.4.0                                                         :  0.4.0 (OK)
pylsp >=1.7.2,<=1.9.0                                                       :  1.10.1 (NOK)
pylsp_black >=1.2.0,<3.0.0                                                  :  2.0.0 (OK)
qdarkstyle >=3.0.2,<3.2.0                                                   :  3.2.3 (NOK)
qstylizer >=0.2.2                                                           :  0.2.2 (OK)
qtawesome >=1.2.1                                                           :  1.3.0 (OK)
qtconsole >=5.4.2,<5.5.0                                                    :  5.5.1 (NOK)
qtpy >=2.1.0                                                                :  2.4.1 (OK)
rtree >=0.9.7                                                               :  1.2.0 (OK)
setuptools >=49.6.0                                                         :  69.0.3 (OK)
sphinx >=0.6.6                                                              :  7.2.6 (OK)
spyder_kernels >=3.0.0b1,<3.0.0b2                                           :  3.0.0b2 (OK)
textdistance >=4.2.0                                                        :  4.6.1 (OK)
three_merge >=0.1.1                                                         :  0.1.1 (OK)
watchdog >=0.10.3                                                           :  3.0.0 (OK)
xdg >=0.26                                                                  :  0.27 (OK)
zmq >=22.1.0                                                                :  25.1.1 (OK)

# Optional:
cython >=0.21                                                               :  3.0.8 (OK)
matplotlib >=3.0.0                                                          :  3.8.2 (OK)
numpy >=1.7                                                                 :  1.26.4 (OK)
pandas >=1.1.1                                                              :  2.2.1 (OK)
scipy >=0.17.0                                                              :  1.11.3 (OK)
sympy >=0.7.3                                                               :  1.12 (OK)
```

### Environment

<details><summary>Environment</summary>

```
Package                       Version
----------------------------- -------------------
aiodns                        3.0.0
aiohttp                       3.9.3
aiosignal                     1.3.1
alabaster                     0.7.16
antlr4-python3-runtime        4.10.1
anyio                         3.7.1
appdirs                       1.4.4
argon2-cffi                   21.3.0
argon2-cffi-bindings          21.2.0
arrow                         1.2.3
astroid                       3.1.0
asttokens                     2.4.1
async-lru                     2.0.4
atomicwrites                  1.4.1
attrs                         23.2.0
autopep8                      2.0.4
Babel                         2.13.1
beautifulsoup4                4.12.3
binaryornot                   0.4.4
black                         24.1.1
bleach                        6.1.0
blivet                        3.9.0
blivet-gui                    2.5.0
blosc2                        2.5.1
bokeh                         2.3.0
Bottleneck                    1.3.7
Brian2                        2.5.4
Brlapi                        0.8.5
Brotli                        1.1.0
cached-property               1.5.2
cachetools                    5.3.2
certifi                       2023.5.7
cffi                          1.16.0
chardet                       5.2.0
charset-normalizer            3.3.2
click                         8.1.7
cloudpickle                   3.0.0
comm                          0.2.1
contourpy                     1.2.0
cookiecutter                  2.5.0
cryptography                  41.0.7
cssselect                     1.1.0
cupshelpers                   1.0
cycler                        0.11.0
Cython                        3.0.8
dasbus                        1.7
dbus-python                   1.3.2
decorator                     5.1.1
defusedxml                    0.7.1
diff-match-patch              20230430
dill                          0.3.8
distro                        1.9.0
dnf                           4.19.0
docstring-to-markdown         0.15
docutils                      0.20.1
entrypoints                   0.4
et-xmlfile                    1.1.0
executing                     2.0.1
fastjsonschema                2.18.0
flake8                        6.0.0
fonttools                     4.49.0
fqdn                          1.5.1
frozenlist                    1.4.1
fs                            2.4.16
fsspec                        2024.2.0
future                        0.18.3
FVS                           0.3.4
gcsfs                         2023.6.0+1.g7cc53d9
gmpy2                         2.1.5
google-api-core               2.11.1
google-auth                   2.28.0
google-auth-oauthlib          0.8.0
google-cloud-core             2.3.3
google-cloud-storage          2.14.0
google-crc32c                 1.5.0
google-resumable-media        2.7.0
googleapis-common-protos      1.62.0
greenlet                      3.0.3
grpcio                        1.48.4
grpcio-status                 1.48.4
h11                           0.14.0
h5py                          3.10.0
helpdev                       0.7.1
html5lib                      1.1
httpcore                      1.0.2
httpx                         0.26.0
icoextract                    0.1.4
idna                          3.6
imageio                       2.34.0
imagesize                     1.4.1
importlib-metadata            6.9.0
inflection                    0.5.1
inkex                         1.3.0
intervaltree                  3.1.0
ipykernel                     6.25.1
ipython                       8.21.0
iso639                        0.1.4
isoduration                   20.11.0
isort                         5.13.2
jaraco.classes                3.3.0
jdcal                         1.4.1
jedi                          0.19.1
jeepney                       0.8.0
jellyfish                     0.9.0
Jinja2                        3.1.3
jinja2-time                   0.2.0
joblib                        1.3.2
json5                         0.9.12
jsonpointer                   2.3
jsonschema                    4.19.1
jsonschema-specifications     2023.11.2
jupyter_client                7.4.9
jupyter_core                  5.1.0
jupyter-events                0.9.0
jupyter-lsp                   2.2.2
jupyter_server                2.12.5
jupyter_server_terminals      0.4.2
jupyterlab                    4.1.0
jupyterlab_pygments           0.3.0
jupyterlab_server             2.25.2
keyring                       24.3.1
kiwisolver                    1.4.5
klusta                        3.0.16
langtable                     0.0.65
lazy_loader                   0.3
lazyarray                     0.5.2
LFPy                          2.3
LFPykit                       0.5.1
libcomps                      0.1.20
libdnf                        0.73.0
libsass                       0.23.0
louis                         3.28.0
lxml                          5.1.0
lz4                           4.3.3
Markdown                      3.5.1
markdown-it-py                3.0.0
MarkupSafe                    2.1.3
matplotlib                    3.8.2
matplotlib-inline             0.1.6
matplotlib-scalebar           0.8.1
mccabe                        0.7.0
mdurl                         0.1.2
MEAutility                    1.5.1
mistune                       2.0.4
more-itertools                10.1.0
MorphIO                       3.3.7
mpmath                        1.3.0
msgpack                       1.0.6
multidict                     6.0.4
mypy-extensions               1.0.0
nbclient                      0.9.0
nbconvert                     7.16.0
nbformat                      5.9.2
ndindex                       1.7
neo                           0.13.0
nest-asyncio                  1.6.0
nest-simulator                3.6
netifaces                     0.11.0
netpyne                       1.0.5
networkx                      3.2.1
NEURON                        8.2.2
nftables                      0.1
nixio                         1.5.2
notebook                      7.0.7
notebook_shim                 0.2.3
numexpr                       2.8.5
numpy                         1.26.4
numpydoc                      1.6.0
oauthlib                      3.2.2
odfpy                         1.4.1
olefile                       0.47
openpyxl                      3.1.2
orjson                        3.9.13
packaging                     23.2
pandas                        2.2.1
pandocfilters                 1.5.0
parso                         0.8.3
pathspec                      0.12.1
pathvalidate                  3.2.0
patool                        1.13
patsy                         0.5.6
pefile                        2023.2.7
pexpect                       4.9.0
pickleshare                   0.7.5
pid                           2.2.3
pillow                        10.2.0
pip                           23.3.2
platformdirs                  3.11.0
pluggy                        1.3.0
ply                           3.11
pooch                         1.5.2
productmd                     1.38
prometheus-client             0.19.0
prompt-toolkit                3.0.41
protobuf                      3.19.6
psutil                        5.9.8
psycopg2                      2.9.9
ptyprocess                    0.7.0
pure-eval                     0.2.2
pwquality                     1.4.5
py-cpuinfo                    9.0.0
pyarrow                       15.0.0
pyasn1                        0.5.1
pyasn1-modules                0.3.0
pycairo                       1.25.1
pycares                       4.3.0
pycodestyle                   2.10.0
pycparser                     2.20
pycups                        2.0.1
pycurl                        7.45.2
pydocstyle                    6.3.0
pyflakes                      3.0.1
pyglet                        1.5.27
Pygments                      2.17.2
PyGObject                     3.46.0
pykickstart                   3.52
pylint                        3.1.0
pylint-venv                   3.0.2
pyls-spyder                   0.4.0
PyMySQL                       1.1.0
PyNN                          0.12.2
pyparsing                     3.1.1
pyparted                      3.13.0
PyQt5                         5.15.10
PyQt5-sip                     12.13.0
PyQtWebEngine                 5.15.6
pyserial                      3.5
PySocks                       1.7.1
python-dateutil               2.8.2
python-json-logger            2.0.4
python-lsp-black              2.0.0
python-lsp-jsonrpc            1.1.2
python-lsp-server             1.10.1
python-meh                    0.51
python-slugify                6.1.2
pytoolconfig                  1.3.1
pytz                          2024.1
pyudev                        0.24.1
pyxdg                         0.27
PyYAML                        6.0.1
pyzmq                         25.1.1
QDarkStyle                    3.2.3
qstylizer                     0.2.2
QtAwesome                     1.3.0
qtconsole                     5.5.1
QtPy                          2.4.1
qtsass                        0.4.0
quantities                    0.15.0
referencing                   0.31.1
requests                      2.31.0
requests-file                 2.0.0
requests-ftp                  0.3.1
requests-oauthlib             1.3.1
rfc3339-validator             0.1.4
rfc3986-validator             0.1.1
rich                          13.7.0
rope                          1.12.0
rpds-py                       0.18.0
rpm                           4.19.1.1
rsa                           4.9
Rtree                         1.2.0
schema                        0.7.5
scikit-image                  0.22.0
scikit-learn                  1.3.1
SciPy                         1.11.3
scour                         0.38.2
SecretStorage                 3.3.3
selinux                       3.6
Send2Trash                    1.8.2
sepolicy                      3.6
setools                       4.4.4
setuptools                    69.0.3
shtab                         1.6.1
simpleline                    1.9.0
six                           1.16.0
sniffio                       1.3.0
snowballstemmer               2.2.0
sortedcontainers              2.4.0
soupsieve                     2.5
Sphinx                        7.2.6
sphinxcontrib-devhelp         1.0.5
sphinxcontrib-htmlhelp        2.0.4
sphinxcontrib-qthelp          1.0.6
sphinxcontrib-serializinghtml 1.1.9
spyder                        6.0.0a1
spyder-kernels                3.0.0b2
SQLAlchemy                    2.0.27
stack-data                    0.6.3
statsmodels                   0.14.1
steps                         3.6.0
sympy                         1.12
systemd-python                235
tables                        3.9.2
tabulate                      0.9.0
terminado                     0.18.0
text-unidecode                1.3
textdistance                  4.6.1
threadpoolctl                 3.3.0
three-merge                   0.1.1
tifffile                      2024.1.30
tinycss2                      1.2.1
tomli                         2.0.1
tomlkit                       0.12.3
tornado                       6.3.3
tqdm                          4.66.2
traitlets                     5.11.2
typing_extensions             4.9.0
ujson                         5.9.0
uri-template                  1.2.0
urllib3                       1.26.18
vkbasalt-cli                  3.1.1.post2
watchdog                      3.0.0
wcwidth                       0.2.6
webcolors                     1.13
webencodings                  0.5.1
websocket-client              1.3.3
whatthepatch                  1.0.2
wurlitzer                     3.0.3
xarray                        2023.8.0
xkbregistry                   0.3
xlrd                          2.0.1
XlsxWriter                    3.1.9
yapf                          0.40.2
yarl                          1.9.2
zipp                          3.17.0
zombie-imp                    0.0.2
zstandard                     0.22.0

```
</details>



Discussion:
Hey @penguinpee, thanks for reporting. What's your `debugpy` version? It's not listed among your environment packages.
None. I don't have `debugpy` installed. It seems it has not yet been packaged for Fedora.

The displayed message is what it says on the box, a warning, due to `debugpy` not being installed. The reason for IPython console not starting seems unrelated to that message:

![ipython_console_message](https://github.com/spyder-ide/spyder/assets/98259694/c5d50511-bf18-4950-93e8-58b8e0418c49)

Is there a way I can easily pass parameters to the `spyder_kernels.console` module? E.g. adding `'--debug'` to the call:

```python
Kernel command: ['/usr/bin/python3', '-Xfrozen_modules=off', '-m', spyder_kernels.console', '-f', '{connection_file}']
```
I upgraded Spyder on my test VM to version 6.0.0a4. While the issue is still there, it appears to be less severe. I found a workaround of some kind.

1. Start Spyder normally
2. Let it settle for a minute or two
3. Close the Ipython Console tab. That will automatically open a new tab. The initial "error" regarding `debugpy_stream` is gone. It now shows:

```
[SpyderKernelApp] WARNING | debugpy_stream undefined, debugging will not be enabled

Python 3.12.2 (main, Feb  7 2024, 00:00:00) [GCC 14.0.1 20240127 (Red Hat 14.0.1-0)]
Type "copyright", "credits" or "license" for more information.

IPython 8.21.0 -- An enhanced Interactive Python.
```

However, there's no prompt, no input.

5. Use the menu to restart the kernel. :tada:

I have a log file available. Maybe there's something in there as to why IPython Console needs some tlc.
> None. I don't have debugpy installed. It seems it has not yet been packaged for Fedora.

Ok, so that's the cause of this problem (I was able to reproduce it locally). But the good news is Spyder's debugger doesn't depend on `debugpy` to work.

To fix this we need to skip that message as harmless, so that the console can start as expected. I'll create PR to do that for our next alpha, to be released soon. 

Resolving patch:
diff --git a/spyder/api/shellconnect/main_widget.py b/spyder/api/shellconnect/main_widget.py
--- a/spyder/api/shellconnect/main_widget.py
+++ b/spyder/api/shellconnect/main_widget.py
@@ -107,8 +107,15 @@ def remove_shellwidget(self, shellwidget):
         shellwidget_id = id(shellwidget)
         if shellwidget_id in self._shellwidgets:
             widget = self._shellwidgets.pop(shellwidget_id)
-            self._stack.removeWidget(widget)
-            self.close_widget(widget)
+
+            # If `widget` is an empty pane, we don't need to remove it from the
+            # stack (because it's the one we need to show since the console is
+            # showing an error) nor try to close it (because it makes no
+            # sense).
+            if not isinstance(widget, PaneEmptyWidget):
+                self._stack.removeWidget(widget)
+                self.close_widget(widget)
+
             self.update_actions()
 
     def set_shellwidget(self, shellwidget):
@@ -131,18 +138,24 @@ def add_errored_shellwidget(self, shellwidget):
         consoles with dead kernels.
         """
         shellwidget_id = id(shellwidget)
-        if shellwidget_id not in self._shellwidgets:
-            widget = PaneEmptyWidget(
-                self,
-                "console-off",
-                _("No connected console"),
-                _("The current console failed to start, so there is no "
-                  "content to show here.")
-            )
 
-            self._stack.addWidget(widget)
-            self._shellwidgets[shellwidget_id] = widget
-            self.set_shellwidget(shellwidget)
+        # This can happen if the kernel started without issues but something is
+        # printed to its stderr stream, which we display as an error in the
+        # console. In that case, we need to remove the current widget
+        # associated to shellwidget and replace it by an empty one.
+        if shellwidget_id in self._shellwidgets:
+            self._shellwidgets.pop(shellwidget_id)
+
+        widget = PaneEmptyWidget(
+            self,
+            "console-off",
+            _("No connected console"),
+            _("The current console failed to start, so there is no "
+              "content to show here.")
+        )
+        self._stack.addWidget(widget)
+        self._shellwidgets[shellwidget_id] = widget
+        self.set_shellwidget(shellwidget)
 
     def create_new_widget(self, shellwidget):
         """Create a widget to communicate with shellwidget."""
diff --git a/spyder/plugins/ipythonconsole/widgets/client.py b/spyder/plugins/ipythonconsole/widgets/client.py
--- a/spyder/plugins/ipythonconsole/widgets/client.py
+++ b/spyder/plugins/ipythonconsole/widgets/client.py
@@ -508,7 +508,11 @@ def is_benign_error(self, error):
             "The following argument was not expected",
             # Avoid showing error for kernel restarts after kernel dies when
             # using an external interpreter
-            "conda.cli.main_run"
+            "conda.cli.main_run",
+            # Warning when debugpy is not available because it's an optional
+            # dependency of IPykernel.
+            # See spyder-ide/spyder#21900
+            "debugpy_stream undefined, debugging will not be enabled",
         ]
 
         return any([err in error for err in benign_errors])


Test patch: