Repository: spyder-ide/spyder
Pull request: PR: Fix error when executing in a dedicated console and the interpreter doesn't have spyder-kernels installed or its right version
<!--- Make sure to read the Contributing Guidelines:                   --->
<!--- https://github.com/spyder-ide/spyder/blob/master/CONTRIBUTING.md --->
<!--- and follow PEP 8, PEP 257 and Spyder's code style:               --->
<!--- https://github.com/spyder-ide/spyder/wiki/Dev:-Coding-Style      --->

## Description of Changes


<!--- Explain what you've done and why --->

Check that the client was created, otherwise it will not be possible to rename


### Issue(s) Resolved

<!--- List the issue(s) below, in the form "Fixes #1234"; one per line --->

Fixes #21884 


### Affirmation

By submitting this Pull Request or typing my (user)name below,
I affirm the [Developer Certificate of Origin](https://developercertificate.org)
with respect to all commits and content included in this PR,
and understand I am releasing the same under Spyder's MIT (Expat) license.

<!--- TYPE YOUR USER/NAME AFTER THE FOLLOWING: --->
I certify the above statement is true and correct:
@jsbautista 
<!--- Thanks for your help making Spyder better for everyone! --->


Problem statement:
AttributeError when executing in a dedicated console and the interpreter was set to an environment without spyder-kernels installed/correct version installed
## Description

### What steps will reproduce the problem?

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

1. Install Anaconda
2. create conda environment with spyder (created from yaml file)
3. open base environment spyder
4. configure python interpreter in preferences to use the not-base environment's python
5. Create a simple matplotlib plotting test
6. From the run menu select "Configuration per file" and then choose "Execute in a dedicated console"
7. The new console tab says an error occurred while starting the kernel and suggests I install spyder-kernels >=2.4 and < 2.5.0

### Traceback
```python-traceback
Traceback (most recent call last):
  File "C:\Users\Stuart\anaconda3\Lib\site-packages\spyder\plugins\ipythonconsole\plugin.py", line 648, in run_script
    self.get_widget().run_script(
  File "C:\Users\Stuart\anaconda3\Lib\site-packages\spyder\plugins\ipythonconsole\widgets\main_widget.py", line 2335, in run_script
    client = self.create_client_for_file(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Stuart\anaconda3\Lib\site-packages\spyder\plugins\ipythonconsole\widgets\main_widget.py", line 1825, in create_client_for_file
    client.allow_rename = False
    ^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'allow_rename'
```

## Versions

* Spyder version: 5.4.3  (conda)
* Python version: 3.11.7 64-bit
* Qt version: 5.15.2
* PyQt5 version: 5.15.10
* Operating System: Windows 10

### Dependencies

```
# Mandatory:
atomicwrites >=1.2.0                             :  1.4.0 (OK)
chardet >=2.0.0                                  :  4.0.0 (OK)
cloudpickle >=0.5.0                              :  2.2.1 (OK)
cookiecutter >=1.6.0                             :  2.5.0 (OK)
diff_match_patch >=20181111                      :  20200713 (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.20.0 (OK)
jedi >=0.17.2,<0.19.0                            :  0.18.1 (OK)
jellyfish >=0.7                                  :  1.0.1 (OK)
jsonschema >=3.2.0                               :  4.19.2 (OK)
keyring >=17.0.0                                 :  23.13.1 (OK)
nbconvert >=4.0                                  :  7.10.0 (OK)
numpydoc >=0.6.0                                 :  1.5.0 (OK)
paramiko >=2.4.0                                 :  2.8.1 (OK)
parso >=0.7.0,<0.9.0                             :  0.8.3 (OK)
pexpect >=4.4.0                                  :  4.8.0 (OK)
pickleshare >=0.4                                :  0.7.5 (OK)
psutil >=5.3                                     :  5.9.0 (OK)
pygments >=2.0                                   :  2.15.1 (OK)
pylint >=2.5.0,<3.0                              :  2.16.2 (OK)
pylint_venv >=2.1.1                              :  2.3.0 (OK)
pyls_spyder >=0.4.0                              :  0.4.0 (OK)
pylsp >=1.7.2,<1.8.0                             :  1.7.2 (OK)
pylsp_black >=1.2.0                              :  1.2.1 (OK)
qdarkstyle >=3.0.2,<3.2.0                        :  3.0.2 (OK)
qstylizer >=0.2.2                                :  0.2.2 (OK)
qtawesome >=1.2.1                                :  1.2.2 (OK)
qtconsole >=5.4.2,<5.5.0                         :  5.4.2 (OK)
qtpy >=2.1.0                                     :  2.4.1 (OK)
rtree >=0.9.7                                    :  1.0.1 (OK)
setuptools >=49.6.0                              :  68.2.2 (OK)
sphinx >=0.6.6                                   :  5.0.2 (OK)
spyder_kernels >=2.4.3,<2.5.0                    :  2.4.4 (OK)
textdistance >=4.2.0                             :  4.2.1 (OK)
three_merge >=0.1.1                              :  0.1.1 (OK)
watchdog >=0.10.3                                :  2.1.6 (OK)
zmq >=22.1.0                                     :  25.1.2 (OK)

# Optional:
cython >=0.21                                    :  None (NOK)
matplotlib >=3.0.0                               :  3.8.0 (OK)
numpy >=1.7                                      :  1.26.4 (OK)
pandas >=1.1.1                                   :  2.1.4 (OK)
scipy >=0.17.0                                   :  1.11.4 (OK)
sympy >=0.7.3                                    :  1.12 (OK)
```

### Environment

<details><summary>Environment</summary>

```
# packages in environment at C:\Users\Stuart\anaconda3\envs\dev:
#
# Name                    Version                   Build  Channel
alabaster                 0.7.12             pyhd3eb1b0_0  
arrow                     1.2.3           py312haa95532_1  
astroid                   2.14.2          py312haa95532_0  
asttokens                 2.4.1              pyhd8ed1ab_0    conda-forge
atomicwrites              1.4.0                      py_0  
attrs                     23.1.0          py312haa95532_0  
autopep8                  2.0.4              pyhd3eb1b0_0  
babel                     2.11.0          py312haa95532_0  
bcrypt                    3.2.0           py312h2bbff1b_1  
beautifulsoup4            4.12.2          py312haa95532_0  
binaryornot               0.4.4              pyhd3eb1b0_1  
black                     23.11.0         py312haa95532_0  
bleach                    4.1.0              pyhd3eb1b0_0  
blosc                     1.21.5               hdccc3a2_0    conda-forge
brotli                    1.1.0                hcfcfb64_1    conda-forge
brotli-bin                1.1.0                hcfcfb64_1    conda-forge
brotli-python             1.1.0           py312h53d5487_1    conda-forge
bzip2                     1.0.8                hcfcfb64_5    conda-forge
ca-certificates           2024.2.2             h56e8100_0    conda-forge
cached-property           1.5.2                hd8ed1ab_1    conda-forge
cached_property           1.5.2              pyha770c72_1    conda-forge
certifi                   2024.2.2        py312haa95532_0  
cffi                      1.16.0          py312h2bbff1b_0  
cftime                    1.6.3           py312ha90f08f_0    conda-forge
chardet                   4.0.0           py312haa95532_1003  
charset-normalizer        3.3.2              pyhd8ed1ab_0    conda-forge
click                     8.1.7           py312haa95532_0  
cloudpickle               2.2.1           py312haa95532_0  
cmocean                   3.1.3              pyhd8ed1ab_0    conda-forge
colorama                  0.4.6              pyhd8ed1ab_0    conda-forge
colorspacious             1.1.2              pyh24bf2e0_0    conda-forge
comm                      0.2.1           py312haa95532_0  
contourpy                 1.2.0           py312h0d7def4_0    conda-forge
cookiecutter              1.7.3              pyhd3eb1b0_0  
cryptography              41.0.7          py312h89fc84f_0  
cycler                    0.12.1             pyhd8ed1ab_0    conda-forge
debugpy                   1.6.7           py312hd77b12b_0  
decorator                 5.1.1              pyhd8ed1ab_0    conda-forge
defusedxml                0.7.1              pyhd3eb1b0_0  
diff-match-patch          20200713           pyhd3eb1b0_0  
dill                      0.3.7           py312haa95532_0  
docstring-to-markdown     0.11            py312haa95532_0  
docutils                  0.18.1          py312haa95532_3  
et_xmlfile                1.1.0              pyhd8ed1ab_0    conda-forge
exceptiongroup            1.2.0              pyhd8ed1ab_2    conda-forge
executing                 2.0.1              pyhd8ed1ab_0    conda-forge
flake8                    7.0.0           py312haa95532_0  
fonttools                 4.49.0          py312he70551f_0    conda-forge
freetype                  2.12.1               hdaf720e_2    conda-forge
gettext                   0.21.1               h5728263_0    conda-forge
glib                      2.80.0               h39d0aa6_0    conda-forge
glib-tools                2.80.0               h0a98069_0    conda-forge
gst-plugins-base          1.22.9               h001b923_0    conda-forge
gstreamer                 1.22.9               hb4038d2_0    conda-forge
gsw                       3.6.17          py312ha90f08f_1    conda-forge
h5py                      3.10.0          nompi_py312h1751c5b_101    conda-forge
hdf4                      4.2.15               h5557f11_7    conda-forge
hdf5                      1.14.3          nompi_h73e8ff5_100    conda-forge
icu                       73.2                 h63175ca_0    conda-forge
idna                      3.6                pyhd8ed1ab_0    conda-forge
imagesize                 1.4.1           py312haa95532_0  
importlib-metadata        7.0.1           py312haa95532_0  
inflection                0.5.1           py312haa95532_1  
intel-openmp              2024.0.0         h57928b3_49841    conda-forge
intervaltree              3.1.0              pyhd3eb1b0_0  
ipykernel                 6.28.0          py312haa95532_0  
ipython                   8.22.2             pyh7428d3b_0    conda-forge
isort                     5.9.3              pyhd3eb1b0_0  
jaraco.classes            3.2.1              pyhd3eb1b0_0  
jedi                      0.19.1             pyhd8ed1ab_0    conda-forge
jellyfish                 1.0.1           py312h36a85e1_0  
jinja2                    3.1.3           py312haa95532_0  
jinja2-time               0.2.0              pyhd3eb1b0_3  
jsonschema                4.19.2          py312haa95532_0  
jsonschema-specifications 2023.7.1        py312haa95532_0  
jupyter_client            8.6.0           py312haa95532_0  
jupyter_core              5.5.0           py312haa95532_0  
jupyterlab_pygments       0.2.2           py312haa95532_0  
keyring                   24.3.1          py312haa95532_0  
kiwisolver                1.4.5           py312h0d7def4_1    conda-forge
krb5                      1.21.2               heb0366b_0    conda-forge
lazy-object-proxy         1.6.0           py312h2bbff1b_0  
lcms2                     2.16                 h67d730c_0    conda-forge
lerc                      4.0.0                h63175ca_0    conda-forge
libaec                    1.1.2                h63175ca_1    conda-forge
libblas                   3.9.0              21_win64_mkl    conda-forge
libbrotlicommon           1.1.0                hcfcfb64_1    conda-forge
libbrotlidec              1.1.0                hcfcfb64_1    conda-forge
libbrotlienc              1.1.0                hcfcfb64_1    conda-forge
libcblas                  3.9.0              21_win64_mkl    conda-forge
libclang                  15.0.7          default_hde6756a_4    conda-forge
libclang13                15.0.7          default_h85b4d89_4    conda-forge
libcurl                   8.5.0                hd5e4a3a_0    conda-forge
libdeflate                1.19                 hcfcfb64_0    conda-forge
libexpat                  2.6.1                h63175ca_0    conda-forge
libffi                    3.4.2                h8ffe710_5    conda-forge
libglib                   2.80.0               h39d0aa6_0    conda-forge
libhwloc                  2.9.3           default_haede6df_1009    conda-forge
libiconv                  1.17                 hcfcfb64_2    conda-forge
libjpeg-turbo             3.0.0                hcfcfb64_1    conda-forge
liblapack                 3.9.0              21_win64_mkl    conda-forge
libnetcdf                 4.9.2           nompi_h07c049d_113    conda-forge
libogg                    1.3.4                h8ffe710_1    conda-forge
libpng                    1.6.43               h19919ed_0    conda-forge
libsodium                 1.0.18               h62dcd97_0  
libspatialindex           1.9.3                h6c2663c_0  
libsqlite                 3.45.2               hcfcfb64_0    conda-forge
libssh2                   1.11.0               h7dfc565_0    conda-forge
libtiff                   4.6.0                h6e2ebb7_2    conda-forge
libvorbis                 1.3.7                h0e60522_0    conda-forge
libwebp-base              1.3.2                hcfcfb64_0    conda-forge
libxcb                    1.15                 hcd874cb_0    conda-forge
libxml2                   2.12.5               hc3477c8_0    conda-forge
libzip                    1.10.1               h1d365fa_3    conda-forge
libzlib                   1.2.13               hcfcfb64_5    conda-forge
lz4-c                     1.9.4                hcfcfb64_0    conda-forge
m2w64-gcc-libgfortran     5.3.0                         6    conda-forge
m2w64-gcc-libs            5.3.0                         7    conda-forge
m2w64-gcc-libs-core       5.3.0                         7    conda-forge
m2w64-gmp                 6.1.0                         2    conda-forge
m2w64-libwinpthread-git   5.0.0.4634.697f757               2    conda-forge
markupsafe                2.1.3           py312h2bbff1b_0  
matplotlib                3.8.3           py312h2e8e312_0    conda-forge
matplotlib-base           3.8.3           py312h26ecaf7_0    conda-forge
matplotlib-inline         0.1.6              pyhd8ed1ab_0    conda-forge
mccabe                    0.7.0              pyhd3eb1b0_0  
mistune                   2.0.4           py312haa95532_0  
mkl                       2024.0.0         h66d3029_49657    conda-forge
more-itertools            10.1.0          py312haa95532_0  
msys2-conda-epoch         20160418                      1    conda-forge
munkres                   1.1.4              pyh9f0ad1d_0    conda-forge
mypy_extensions           1.0.0           py312haa95532_0  
nbclient                  0.8.0           py312haa95532_0  
nbconvert                 7.10.0          py312haa95532_0  
nbformat                  5.9.2           py312haa95532_0  
nest-asyncio              1.6.0           py312haa95532_0  
netcdf4                   1.6.5           nompi_py312he4da9c3_100    conda-forge
numpy                     1.26.4          py312h8753938_0    conda-forge
numpydoc                  1.5.0           py312haa95532_0  
openjpeg                  2.5.2                h3d672ee_0    conda-forge
openpyxl                  3.1.2           py312he70551f_1    conda-forge
openssl                   3.2.1                hcfcfb64_0    conda-forge
packaging                 24.0               pyhd8ed1ab_0    conda-forge
pandas                    2.2.1           py312h2ab9e98_0    conda-forge
pandocfilters             1.5.0              pyhd3eb1b0_0  
paramiko                  2.8.1              pyhd3eb1b0_0  
parso                     0.8.3              pyhd8ed1ab_0    conda-forge
pathspec                  0.10.3          py312haa95532_0  
pcre2                     10.43                h17e33f8_0    conda-forge
pexpect                   4.8.0              pyhd3eb1b0_3  
pickleshare               0.7.5                   py_1003    conda-forge
pillow                    10.2.0          py312he768995_0    conda-forge
pip                       24.0               pyhd8ed1ab_0    conda-forge
platformdirs              3.10.0          py312haa95532_0  
pluggy                    1.0.0           py312haa95532_1  
ply                       3.11                       py_1    conda-forge
poyo                      0.5.0              pyhd3eb1b0_0  
prompt-toolkit            3.0.42             pyha770c72_0    conda-forge
psutil                    5.9.0           py312h2bbff1b_0  
pthread-stubs             0.4               hcd874cb_1001    conda-forge
pthreads-win32            2.9.1                hfa6e2cd_3    conda-forge
ptyprocess                0.7.0              pyhd3eb1b0_2  
pure_eval                 0.2.2              pyhd8ed1ab_0    conda-forge
pycodestyle               2.11.1          py312haa95532_0  
pycparser                 2.21               pyhd3eb1b0_0  
pydocstyle                6.3.0           py312haa95532_0  
pyflakes                  3.2.0           py312haa95532_0  
pygments                  2.17.2             pyhd8ed1ab_0    conda-forge
pylint                    2.16.2          py312haa95532_0  
pylint-venv               3.0.3           py312haa95532_0  
pyls-spyder               0.4.0              pyhd3eb1b0_0  
pynacl                    1.5.0           py312h8cc25b3_0  
pyparsing                 3.1.2              pyhd8ed1ab_0    conda-forge
pyqt                      5.15.9          py312he09f080_5    conda-forge
pyqt5-sip                 12.12.2         py312h53d5487_5    conda-forge
pyqtwebengine             5.15.9          py312hca0710b_5    conda-forge
pyserial                  3.5                pyhd8ed1ab_0    conda-forge
pysocks                   1.7.1              pyh0701188_6    conda-forge
python                    3.12.2          h2628c8c_0_cpython    conda-forge
python-dateutil           2.9.0              pyhd8ed1ab_0    conda-forge
python-fastjsonschema     2.16.2          py312haa95532_0  
python-lsp-black          2.0.0           py312haa95532_0  
python-lsp-jsonrpc        1.1.2              pyhd3eb1b0_0  
python-lsp-server         1.10.0          py312haa95532_0  
python-slugify            5.0.2              pyhd3eb1b0_0  
python-tzdata             2024.1             pyhd8ed1ab_0    conda-forge
python_abi                3.12                    4_cp312    conda-forge
pytoolconfig              1.2.6           py312haa95532_0  
pytz                      2024.1             pyhd8ed1ab_0    conda-forge
pywin32                   305             py312h2bbff1b_0  
pywin32-ctypes            0.2.2           py312haa95532_0  
pyyaml                    6.0.1           py312he70551f_1    conda-forge
pyzmq                     25.1.2          py312hd77b12b_0  
qdarkstyle                3.2.3              pyhd3eb1b0_0  
qstylizer                 0.2.2           py312haa95532_0  
qt-main                   5.15.8              h9e85ed6_19    conda-forge
qt-webengine              5.15.9               h5bd16bc_7  
qtawesome                 1.2.2           py312haa95532_0  
qtconsole                 5.5.1           py312haa95532_0  
qtpy                      2.4.1           py312haa95532_0  
referencing               0.30.2          py312haa95532_0  
requests                  2.31.0             pyhd8ed1ab_0    conda-forge
rope                      1.12.0          py312haa95532_0  
rpds-py                   0.10.6          py312h062c2fa_0  
rtree                     1.0.1           py312h2eaa2aa_0  
scipy                     1.12.0          py312h8753938_2    conda-forge
setuptools                69.1.1             pyhd8ed1ab_0    conda-forge
sip                       6.7.12          py312h53d5487_0    conda-forge
six                       1.16.0             pyh6c4a22f_0    conda-forge
snappy                    1.1.10               hfb803bf_0    conda-forge
snowballstemmer           2.2.0              pyhd3eb1b0_0  
sortedcontainers          2.4.0              pyhd3eb1b0_0  
soupsieve                 2.5             py312haa95532_0  
sphinx                    5.0.2           py312haa95532_0  
sphinxcontrib-applehelp   1.0.2              pyhd3eb1b0_0  
sphinxcontrib-devhelp     1.0.2              pyhd3eb1b0_0  
sphinxcontrib-htmlhelp    2.0.0              pyhd3eb1b0_0  
sphinxcontrib-jsmath      1.0.1              pyhd3eb1b0_0  
sphinxcontrib-qthelp      1.0.3              pyhd3eb1b0_0  
sphinxcontrib-serializinghtml 1.1.5              pyhd3eb1b0_0  
spyder                    5.5.1           py312h2e8e312_0    conda-forge
spyder-kernels            2.5.0           py312haa95532_0  
stack_data                0.6.2              pyhd8ed1ab_0    conda-forge
tbb                       2021.11.0            h91493d7_1    conda-forge
text-unidecode            1.3                pyhd3eb1b0_0  
textdistance              4.2.1              pyhd3eb1b0_0  
three-merge               0.1.1              pyhd3eb1b0_0  
tinycss2                  1.2.1           py312haa95532_0  
tk                        8.6.13               h5226925_1    conda-forge
toml                      0.10.2             pyhd8ed1ab_0    conda-forge
tomli                     2.0.1              pyhd8ed1ab_0    conda-forge
tomlkit                   0.11.1          py312haa95532_0  
tornado                   6.4             py312he70551f_0    conda-forge
traitlets                 5.14.2             pyhd8ed1ab_0    conda-forge
typing_extensions         4.10.0             pyha770c72_0    conda-forge
tzdata                    2024a                h0c530f3_0    conda-forge
ucrt                      10.0.22621.0         h57928b3_0    conda-forge
ujson                     5.4.0           py312hd77b12b_0  
unidecode                 1.2.0              pyhd3eb1b0_0  
urllib3                   2.2.1              pyhd8ed1ab_0    conda-forge
vc                        14.3                hcf57466_18    conda-forge
vc14_runtime              14.38.33130         h82b7239_18    conda-forge
vs2015_runtime            14.38.33130         hcb4865c_18    conda-forge
watchdog                  2.1.6           py312haa95532_0  
wcwidth                   0.2.13             pyhd8ed1ab_0    conda-forge
webencodings              0.5.1           py312haa95532_2  
whatthepatch              1.0.2           py312haa95532_0  
wheel                     0.42.0             pyhd8ed1ab_0    conda-forge
win_inet_pton             1.1.0              pyhd8ed1ab_6    conda-forge
wrapt                     1.14.1          py312h2bbff1b_0  
xarray                    2024.2.0           pyhd8ed1ab_0    conda-forge
xorg-libxau               1.0.11               hcd874cb_0    conda-forge
xorg-libxdmcp             1.1.3                hcd874cb_0    conda-forge
xz                        5.2.6                h8d14728_0    conda-forge
yaml                      0.2.5                h8ffe710_2    conda-forge
yapf                      0.40.2          py312haa95532_0  
zeromq                    4.3.5                hd77b12b_0  
zipp                      3.17.0          py312haa95532_0  
zlib                      1.2.13               hcfcfb64_5    conda-forge
zstd                      1.5.5                h12be248_0    conda-forge

```
</details>

Hints from issue discussion:
Hey @s-pearce, thanks for reporting. It seems the problem has to do with two things:
1. The environment you created from a yaml file doesn't have the right version of Spyder-kernels that's required for the Spyder you have in your base env.
2. We're not guarding against that when trying to create a dedicated console to run code, which is causing the bug you reported.

The solution for now is for you to install Spyder 5.4 in your non-base env. Unfortunately, Spyder and Spyder-kernels versions need to paired to work as expected (e.g. Spyder 5.4 with Spyder-kernels 2.4).

We'll fix this error with dedicated consoles in Spyder 6, to be released in a couple of months. But that won't avoid the need to have the right version of Spyder-kernels in other envs.
Thanks @ccordoba12, I agree that would be the better solution and that is kind of where my learning from yesterday led me.  However, there also seems to be a bug within Conda/Anaconda on Windows where if I create a non-base environment with spyder and the correct spyder-kernels version, I get an error during boot up saying it does not have permission to copy the icon \font file under %userprofile%\AppData\Local\Microsoft\Windows\Fonts\codicon.ttf. 
This problem doesn't seem to occur with the base environment spyder install, so I have to assume the fault lies within conda or anaconda.   Anyway, not ideal, but I just need to make my base environment work as my non-base environment  should.  
> there also seems to be a bug within Conda/Anaconda on Windows where if I create a non-base environment with spyder and the correct spyder-kernels version, I get an error during boot up saying it does not have permission to copy the icon \font file under %userprofile%\AppData\Local\Microsoft\Windows\Fonts\codicon.ttf.

That's actually not a problem with Anaconda/conda but a bug in one of our libraries: https://github.com/spyder-ide/qtawesome/issues/236. We'll try to fix it in its next version, to be released soon.

Commit message: fix error

Patch to review:
diff --git a/spyder/plugins/ipythonconsole/widgets/main_widget.py b/spyder/plugins/ipythonconsole/widgets/main_widget.py
index 974eaf454b4..7878850c16a 100644
--- a/spyder/plugins/ipythonconsole/widgets/main_widget.py
+++ b/spyder/plugins/ipythonconsole/widgets/main_widget.py
@@ -1851,9 +1851,10 @@ def create_client_for_file(self, filename, is_cython=False):
         self.master_clients -= 1
 
         # Rename client tab with filename
-        client.allow_rename = False
-        tab_text = self.disambiguate_fname(filename)
-        self.rename_client_tab(client, tab_text)
+        if (client):
+            client.allow_rename = False
+            tab_text = self.disambiguate_fname(filename)
+            self.rename_client_tab(client, tab_text)
 
         return client
 


Code review comments:
diff_hunk: @@ -1851,9 +1851,10 @@ def create_client_for_file(self, filename, is_cython=False):
         self.master_clients -= 1
 
         # Rename client tab with filename
-        client.allow_rename = False
-        tab_text = self.disambiguate_fname(filename)
-        self.rename_client_tab(client, tab_text)
+        if (client):
path: spyder/plugins/ipythonconsole/widgets/main_widget.py
text: @user1:
```suggestion
        if client is not None:
```

According to issue #21884, the problem happens when we reach this point and `client` is `None`. So we can improve a little bit this validation.