Repository: spyder-ide/spyder

Issue:
Error when starting kernel: "The following argument was not expected: /path/to/environment/"
<!--- **PLEASE READ:** When submitting here, please ensure you've completed the following checklist and checked the boxes to confirm. Issue reports without it may be closed. Thanks! --->

### Issue Report Checklist

* [x] Searched the [issues page](https://github.com/spyder-ide/spyder/issues?q=is%3Aissue) for similar reports
* [x] Read the relevant sections of the [Spyder Troubleshooting Guide](https://github.com/spyder-ide/spyder/wiki/Troubleshooting-Guide-and-FAQ) and followed its advice
* [x] Reproduced the issue after updating with ``conda update spyder`` (or ``pip``, if not using Anaconda)
* [x] Could not reproduce inside ``jupyter qtconsole`` (if console-related) -- **could not reproduce in IPython: running jupyter qtconsole gave an error (see below)**
* [x] Tried basic troubleshooting (if a bug/error)
    * [x] Restarted Spyder
    * [x] Reset preferences with ``spyder --reset``
    * [x] Reinstalled the latest version of [Anaconda](https://www.anaconda.com/download/) -- **Did reinstall, but using Miniconda, not Anaconda**
    * [x] Tried the other applicable steps from the Troubleshooting Guide
* [x] Completed the **Problem Description**, **Steps to Reproduce** and **Version** sections below

Error from `jupyter qtconsole`:
```
(spyder-env) C:\WINDOWS\system32>jupyter qtconsole
usage: jupyter [-h] [--version] [--config-dir] [--data-dir] [--runtime-dir] [--paths] [--json] [--debug] [subcommand]

Jupyter: Interactive Computing

positional arguments:
  subcommand     the subcommand to launch

optional arguments:
  -h, --help     show this help message and exit
  --version      show the versions of core jupyter packages and exit
  --config-dir   show Jupyter config dir
  --data-dir     show Jupyter data dir
  --runtime-dir  show Jupyter runtime dir
  --paths        show all Jupyter paths. Add --json for machine-readable format.
  --json         output paths as machine-readable json
  --debug        output debug information about paths

Available subcommands: kernel kernelspec migrate run script troubleshoot

Jupyter command `jupyter-qtconsole` not found.

(spyder-env) C:\WINDOWS\system32>
```
## Problem Description



### What steps reproduce the problem?

1. Install new version of Spyder (5.3.3)
2. Agree to uninstall previous version
3. Start Spyder

### What is the expected output? What do you see instead?
Expected: Start Spyder with an active prompt in the IPython console

Instead: 
 * "An error ocurred while starting the kernel"
 * "The following argument was not expected: C:/ProgramData/Miniconda3/envs/spyder‑env"
 * Followed by other errors


### Paste Traceback/Error Below (if applicable)
<!--- Copy from error dialog or View > Panes > Internal Console --->

```python-traceback

The following argument was not expected: C:/ProgramData/Miniconda3/envs/spyder-env
Run with --help for more information.

```

## 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.3
* Python version: 3.9.13
* Qt version: Unknown
* PyQt version: Unknown
* Operating System name/version: Windows 11 Enterprise version 21H2

### 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.14.0 (OK)
keyring >=17.0.0                     :  23.8.2 (OK)
nbconvert >=4.0                      :  7.0.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.13.0 (OK)
pylint >=2.5.0;<3.0                  :  2.15.0 (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.2;<5.4.0             :  5.3.2 (OK)
qtpy >=2.1.0                         :  2.2.0 (OK)
rtree >=0.9.7                        :  1.0.0 (OK)
setuptools >=49.6.0                  :  65.3.0 (OK)
sphinx >=0.6.6                       :  5.1.1 (OK)
spyder_kernels >=2.3.3;<2.4.0        :  2.3.3 (OK)
textdistance >=4.2.0                 :  4.4.0 (OK)
three_merge >=0.1.1                  :  0.1.1 (OK)
watchdog                             :  2.1.9 (OK)
zmq >=22.1.0                         :  23.2.1 (OK)

# Optional:
cython >=0.21                        :  0.29.32 (OK)
matplotlib >=3.0.0                   :  3.5.3 (OK)
numpy >=1.7                          :  1.22.4 (OK)
pandas >=1.1.1                       :  1.4.3 (OK)
scipy >=0.17.0                       :  1.9.1 (OK)
sympy >=0.7.3                        :  1.11 (OK)

# Spyder plugins:
spyder_terminal.terminalplugin 1.2.2 :  1.2.2 (OK)


```



Discussion:
Hey @erickb, thanks for reporting. It seems you installed Spyder using our Windows installer and then you installed Miniconda to use additional Python packages.

Is that correct?
Hi, Carlos,

Thanks for getting back to me. I already had a Miniconda3/Spyder installation. I was prompted to download the most recent version of Spyder, so I did that and installed it.

When I started, I got a large number of errors, but I updated conda, added conda-forge and got the spyder-kernel packages, and updated all of my modules. That took care of nearly everything, but I still go the error message that I reported.

So, I:

 1.  Reset my Spyder settings
 2.  Pointed Spyder back to Minconda3, and my environment (envs/spyder-env/)
 3.  Restarted and still go the error
 4.  Deleted my conda installation and reinstalled it, created a new spyder-env, and installed spyder-kernel packages and spyder
 5.  Restarted and still go the error
 6.  Completely reinstalled Spyder and still got the error

I hope that makes sense.

Eric



[https://www.sei.org/signature/SEI.png]<https://www.sei.org/?utm_source=email-signature>

[https://www.sei.org/signature/twitter.png]<https://twitter.com/SEIresearch>[https://www.sei.org/signature/facebook.png]<http://www.facebook.com/StockholmEnvironmentInstitute>[https://www.sei.org/signature/linkedin.png]<http://www.linkedin.com/company/stockholm-environment-institute>
        Eric Kemp-Benedict
Equitable Transitions Program Director
***@***.***
+1 (617) 590-5436
Stockholm Environment Institute
11 Curtis Avenue, Somerville, MA 02144-1224, USA

Pronouns: he, him, his
From: Carlos Cordoba ***@***.***>
Sent: Sunday, September 4, 2022 2:47 PM
To: spyder-ide/spyder ***@***.***>
Cc: Eric Kemp-Benedict ***@***.***>; Mention ***@***.***>
Subject: Re: [spyder-ide/spyder] Error when starting kernel: "The following argument was not expected: /path/to/environment/" (Issue #19298)


Hey @erickb<https://github.com/erickb>, thanks for reporting. It seems you installed Spyder using our Windows installer and then you installed Miniconda to use additional Python packages.

Is that correct?

—
Reply to this email directly, view it on GitHub<https://github.com/spyder-ide/spyder/issues/19298#issuecomment-1236395005>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AAFYPIFWWEJM4ZVBYZ3T63DV4TVDPANCNFSM6AAAAAAQEBG7ZU>.
You are receiving this because you were mentioned.Message ID: ***@***.******@***.***>>

Hi, @ccordoba12
An error occurred while starting the IPython kernel
I have the same problem when use a custom Python interpreter.
With the default Python interpreter, no problem
I installed spyder using windows installer

![image](https://user-images.githubusercontent.com/1759365/189804715-2468933f-1066-4744-96f4-7e6c190d5913.png)

![image](https://user-images.githubusercontent.com/1759365/189804767-79741de3-58bc-47c8-af60-a9a29b9d67f8.png)

## Versions
* Spyder version: 5.3.3  (standalone)
* Python version: 3.8.10 64-bit
* Qt version: 5.15.2
* PyQt5 version: 5.15.7
* Operating System: Windows 10

## Dependencies
### 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.14.0 (OK)
keyring >=17.0.0                     :  23.8.2 (OK)
nbconvert >=4.0                      :  7.0.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.13.0 (OK)
pylint >=2.5.0;<3.0                  :  2.15.0 (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.2;<5.4.0             :  5.3.2 (OK)
qtpy >=2.1.0                         :  2.2.0 (OK)
rtree >=0.9.7                        :  1.0.0 (OK)
setuptools >=49.6.0                  :  65.3.0 (OK)
sphinx >=0.6.6                       :  5.1.1 (OK)
spyder_kernels >=2.3.3;<2.4.0        :  2.3.3 (OK)
textdistance >=4.2.0                 :  4.4.0 (OK)
three_merge >=0.1.1                  :  0.1.1 (OK)
watchdog                             :  2.1.9 (OK)
zmq >=22.1.0                         :  23.2.1 (OK)

### Optional:
cython >=0.21                        :  0.29.32 (OK)
matplotlib >=3.0.0                   :  3.5.3 (OK)
numpy >=1.7                          :  1.22.4 (OK)
pandas >=1.1.1                       :  1.4.3 (OK)
scipy >=0.17.0                       :  1.9.1 (OK)
sympy >=0.7.3                        :  1.11 (OK)

### Spyder plugins:
spyder_terminal.terminalplugin 1.2.2 :  1.2.2 (OK)



Just in case, this could be related with the behavior I was able to reproduce at https://github.com/spyder-ide/spyder/issues/16562#issuecomment-1202968973 (related with the installation using the `For all users installation` vs `Just for the current user installation`)
@dalthviz, yeah, it looks like the same error. Should we catch this message as a benign error? 
I think it could be worty to understand why this happens, also I'm not sure if by just letting the error pass enables to fully use the console or if the console env is actually not activated correctly
Ok, no problem. Then, should we close this one in favor of #16562?
Actually re-reading #16562 seems like the original issue there is different to the error `The following argument was not expected: /path/to/environment/`. I think the issues are related but not completly the same. So actually maybe is worthy to keep both :+1:
This error also appears when launching Spyder after a "install for just me" installation (although path has been modified). 

Also, in Spyder, running a new kernel usually allows me to use the console. However, the warning still persists afterwards. 

First initialization:
![image](https://user-images.githubusercontent.com/26440812/192058023-3e133926-b4b7-4364-b227-72f9b582275a.png)

After starting new kernel:
![image](https://user-images.githubusercontent.com/26440812/192058134-3d26ed68-85d6-4d36-a6c7-99341d0f4256.png)

Hopefully this provides a clue to the issue.
@dalthviz, according to @woudreus's comment above and @Pigankle's one in https://github.com/spyder-ide/spyder/issues/19731#issuecomment-1276576712, I think this is a benign error, so we should catch and dismiss it.

My guess is that the error doesn't show up the second time a console is started because we've cached the kernel parameters in the previous run, so the kernel starts really fast and that doesn't give time to block the console.
@ccordoba12 to be clear, the first time the error appears (on startup), the kernel will not work. If if I restart the kernel by closing the tab, then the error reappears but it works anyways.
Yep, that's what I understood from your comment and it's very similar to what @woudreus said above. That's why I think this is a benign error, i.e. a spurious one that we can simply skip.

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
@@ -588,7 +588,9 @@ def is_benign_error(self, error):
             "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."
+            "Set PYDEVD_DISABLE_FILE_VALIDATION=1 to disable this validation.",
+            # Argument not expected error. See spyder-ide/spyder#19298
+            "The following argument was not expected"
         ]
 
         return any([err in error for err in benign_errors])


Test patch: