Repository: spyder-ide/spyder

Issue:
PYDEVD kernel error when starting Spyder
## Problem Description

Hi all, I receive this kernel error when Spyder starts up every time I start it. I have to restart the kernel a few times for it to begin working correctly.

![image](https://user-images.githubusercontent.com/62626513/182435529-85b069f8-d5bf-4116-9c72-af22bd211329.png)

### What steps reproduce the problem?

1. Starting Spyder for the first time 

### What is the expected output? What do you see instead?

if I force restart the kernel a few times, the kernel will begin working every once in a while.

### Paste Traceback/Error Below (if applicable)
<!--- Copy from error dialog or View > Panes > Internal Console --->

```An error ocurred while starting the kernel
0.01s ‑ Debugger warning: The os.path.realpath.__code__.co_filename (ntpath.py)
0.00s ‑ is not absolute, which may make the debugger miss breakpoints.
0.00s ‑ Note: Debugging will proceed. Set PYDEVD_DISABLE_FILE_VALIDATION=1 to disable this validation.

```

## Versions
<!--- You can get this information from Help > About Spyder...
or (if Spyder won't launch) the "conda list" command
from the Anaconda Prompt/Terminal/command line. --->

* Spyder version: 5.3.2
* Python version: 3.8.10
* Qt version: 5.15.2
* PyQt version: 5.15.7
* Operating System name/version: Win 11

### Dependencies
<!--- Please go to the menu entry Help > Dependencies,
press the Copy to clipboard button and paste below --->

```
# Mandatory:
atomicwrites >=1.2.0                 :  1.4.1 (OK)
chardet >=2.0.0                      :  5.0.0 (OK)
cloudpickle >=0.5.0                  :  2.1.0 (OK)
cookiecutter >=1.6.0                 :  2.1.1 (OK)
diff_match_patch >=20181111          :  20200713 (OK)
intervaltree                         :  None (OK)
IPython >=7.31.1;<8.0.0              :  7.34.0 (OK)
jedi >=0.17.2;<0.19.0                :  0.18.1 (OK)
jellyfish >=0.7                      :  0.9.0 (OK)
jsonschema >=3.2.0                   :  4.7.2 (OK)
keyring >=17.0.0                     :  23.6.0 (OK)
nbconvert >=4.0                      :  6.5.0 (OK)
numpydoc >=0.6.0                     :  1.4.0 (OK)
paramiko >=2.4.0                     :  2.11.0 (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.1 (OK)
pygments >=2.0                       :  2.12.0 (OK)
pylint >=2.5.0;<3.0                  :  2.14.4 (OK)
pyls_spyder >=0.4.0                  :  0.4.0 (OK)
pylsp >=1.5.0;<1.6.0                 :  1.5.0 (OK)
pylsp_black >=1.2.0                  :  1.2.1 (OK)
qdarkstyle >=3.0.2;<3.1.0            :  3.0.3 (OK)
qstylizer >=0.1.10                   :  0.2.1 (OK)
qtawesome >=1.0.2                    :  1.1.1 (OK)
qtconsole >=5.3.0;<5.4.0             :  5.3.1 (OK)
qtpy >=2.1.0                         :  2.1.0 (OK)
rtree >=0.9.7                        :  1.0.0 (OK)
setuptools >=49.6.0                  :  63.1.0 (OK)
sphinx >=0.6.6                       :  5.0.2 (OK)
spyder_kernels >=2.3.2;<2.4.0        :  2.3.2 (OK)
textdistance >=4.2.0                 :  4.3.0 (OK)
three_merge >=0.1.1                  :  0.1.1 (OK)
watchdog                             :  2.1.9 (OK)
zmq >=22.1.0                         :  23.2.0 (OK)

# Optional:
cython >=0.21                        :  0.29.30 (OK)
matplotlib >=3.0.0                   :  3.5.2 (OK)
numpy >=1.7                          :  1.22.4 (OK)
pandas >=1.1.1                       :  1.4.3 (OK)
scipy >=0.17.0                       :  1.8.1 (OK)
sympy >=0.7.3                        :  1.10.1 (OK)

# Spyder plugins:
spyder_terminal.terminalplugin 1.2.2 :  1.2.2 (OK)

```



Discussion:
Hi @Eilermoon thank you for the feedback! Seems like you installed Spyder using the standalone application, right? This seems like a duplicate of https://github.com/spyder-ide/spyder/issues/17552 but since you are using 5.3.2 the fix should be already in your installation 🤔 

Could it be possible for you to uninstall and reinstall? Also, just in case from where did you downloaded the standalone installer?

Let us know!
Hey @dalthviz, thanks for the quick reply! Apologies I didn't find that #17552 ticket before posting this.

I'll try to reinstall and see if it's still an issue. I downloaded via the installer from https://www.spyder-ide.org/.
After uninstalling, re-downloading from the spyder-ide.org website and re-installing, I still see the same error when starting Spyder. The version downloaded and running now is Spyder IDE 5.3.2
🤔 not sure what could be happening but @Eilermoon could you run from the internal console (you can make it visible by going to `View > Panes > Internal Console`) the following code and after that check if the `environ` var has an entry for `PYDEVD_DISABLE_FILE_VALIDATION` from the Variable Explorer?:

     spy.window.ipyconsole.execute_code("import os; environ = dict(os.environ)")

Let us know!

@dalthviz, I think the solution to this problem is setting `PYDEVD_DISABLE_FILE_VALIDATION=1` in the kernel. That should prevent that warning from appearing, which is generated by a dependency of the Debugpy package.
That's the thing @ccordoba12 we are already doing that here:

https://github.com/spyder-ide/spyder/blob/54c55f57f1c4d3d52acad5f1599e18829017e6e9/spyder/plugins/ipythonconsole/utils/kernelspec.py#L189-L197

@Eilermoon maybe you are using a custom interpreter ? 
Sorry, I totally forgot about that! I thought we were just catching and skipping the spurious message that prevents the kernel to be shown.

@dalthviz, then could you test that `PYDEVD_DISABLE_FILE_VALIDATION` is set for kernels on the Windows app? Perhaps we're failing to do that somehow.
That's why I was suggesting to run from the internal console `spy.window.ipyconsole.execute_code("import os; environ = dict(os.environ)")`. If I check the dict I can see the `PYDEVD_DISABLE_FILE_VALIDATION` env var:

![imagen](https://user-images.githubusercontent.com/16781833/182647819-eecb6b70-e08b-46ba-9b78-f2f1faf26bfa.png)


Hey @dalthviz, when I enable the 'Internal console' pane, I get this error many times: 
![image](https://user-images.githubusercontent.com/62626513/182894020-ab915b2e-ceb0-46cf-84f4-b41a28e4d003.png)

After this, if I try to run the line of code you gave above, it doesn't react in any way. No variables populate in the 'Variable Explorer'.

![image](https://user-images.githubusercontent.com/62626513/182894153-61f5e5d5-9f52-4f5b-9d14-3a4a5466c9c9.png)

🤔 right, checking I think if an error gets detected the shell is being shutdown. @Eilermoon could you add the `Note: Debugging will proceed. Set PYDEVD_DISABLE_FILE_VALIDATION=1 to disable this validation.` as a new entry for the `benign_errors` list at https://github.com/spyder-ide/spyder/blob/1172bb4678970250c8e8f46a70a151c00d32d69f/spyder/plugins/ipythonconsole/widgets/client.py#L576-L592

With the default standalone installer installation dir the `client.py`  file should be at `C:\Users\<your user>\AppData\Local\Programs\Spyder\pkgs\spyder\plugins\ipythonconsole\widgets\client.py` if you did the installation for only the current user.

Let us know if the change there helps!
@dalthviz, a user that reported the same problem on issue #18977 confirmed that the fix you mentioned on https://github.com/spyder-ide/spyder/issues/18908#issuecomment-1205494761 solves the problem. So please go ahead and implement it.

Resolving patch:
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
@@ -587,7 +587,10 @@ def is_benign_error(self, error):
             # disable secure writes.
             "WARNING: Insecure writes have been enabled via environment",
             # Old error
-            "No such comm"
+            "No such comm",
+            # PYDEVD debug warning message. See spyder-ide/spyder#18908
+            "Note: Debugging will proceed. "
+            "Set PYDEVD_DISABLE_FILE_VALIDATION=1 to disable this validation."
         ]
 
         return any([err in error for err in benign_errors])


Test patch: