Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spyder kernel unable to start after switching default environment to Anaconda #20942

Closed
TradeMark17 opened this issue May 18, 2023 · 9 comments
Closed

Comments

@TradeMark17
Copy link

Description

What steps will reproduce the problem?

Sorry in advance, I do not know much about environments or windows applications.

I have Anaconda and Spyder (5.4.3) both downloaded on my Windows desktop, and I am running Spyder from the .exe file (because it's broken through Anaconda Navigator). Python version 3.10.9.

I need to use the module/package "torch", which is not already downloaded with Spyder. I followed the instructions on the PyTorch website, and the package got downloaded to an Anaconda folder. Spyder doesn't see "torch" when run with the default environment, but when I switch the default environment to that which is printed out by this command in the Anaconda Powershell Prompt:

python -c "import sys; print(sys.executable)"

the kernel won't start - error message: "& was unexpected at this time". I've uninstalled and reinstalled Spyder and Anaconda 3 times so far and each time I get more errors, I am going crazy.

Traceback

Traceback (most recent call last):
  File "D:\Spyder\pkgs\jupyter_client\manager.py", line 88, in wrapper
    self._ready.set_result(None)
asyncio.exceptions.InvalidStateError: invalid state

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\Spyder\pkgs\qtconsole\manager.py", line 27, in poll
    super().poll()
  File "D:\Spyder\pkgs\jupyter_client\restarter.py", line 140, in poll
    self.kernel_manager.restart_kernel(now=True, newports=newports)
  File "D:\Spyder\pkgs\jupyter_core\utils\__init__.py", line 166, in wrapped
    return loop.run_until_complete(inner)
  File "asyncio\base_events.py", line 616, in run_until_complete
  File "D:\Spyder\pkgs\jupyter_client\manager.py", line 555, in _async_restart_kernel
    await self._async_start_kernel(**self._launch_args)
  File "D:\Spyder\pkgs\jupyter_client\manager.py", line 91, in wrapper
    self._ready.set_exception(e)
asyncio.exceptions.InvalidStateError: invalid state

Versions

  • Spyder version: 5.4.3 (standalone)
  • Python version: 3.8.10 64-bit
  • Qt version: 5.15.2
  • PyQt5 version: 5.15.9
  • Operating System: Windows 10

Dependencies

# Mandatory:
atomicwrites >=1.2.0                             :  1.4.1 (OK)
chardet >=2.0.0                                  :  5.1.0 (OK)
cloudpickle >=0.5.0                              :  2.2.1 (OK)
cookiecutter >=1.6.0                             :  2.1.1 (OK)
diff_match_patch >=20181111                      :  20200713 (OK)
intervaltree                                     :  None (OK)
IPython >=7.31.1,<9.0.0,!=8.8.0,!=8.9.0,!=8.10.0 :  8.12.0 (OK)
jedi >=0.17.2,<0.19.0                            :  0.18.2 (OK)
jellyfish >=0.7                                  :  0.11.2 (OK)
jsonschema >=3.2.0                               :  4.17.3 (OK)
keyring >=17.0.0                                 :  23.13.1 (OK)
nbconvert >=4.0                                  :  7.3.0 (OK)
numpydoc >=0.6.0                                 :  1.5.0 (OK)
paramiko >=2.4.0                                 :  3.1.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.4 (OK)
pygments >=2.0                                   :  2.14.0 (OK)
pylint >=2.5.0,<3.0                              :  2.17.2 (OK)
pylint_venv >=2.1.1                              :  3.0.1 (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.1 (OK)
qstylizer >=0.2.2                                :  0.2.2 (OK)
qtawesome >=1.2.1                                :  1.2.3 (OK)
qtconsole >=5.4.2,<5.5.0                         :  5.4.2 (OK)
qtpy >=2.1.0                                     :  2.3.1 (OK)
rtree >=0.9.7                                    :  1.0.1 (OK)
setuptools >=49.6.0                              :  67.6.1 (OK)
sphinx >=0.6.6                                   :  6.1.3 (OK)
spyder_kernels >=2.4.3,<2.5.0                    :  2.4.3 (OK)
textdistance >=4.2.0                             :  4.5.0 (OK)
three_merge >=0.1.1                              :  0.1.1 (OK)
watchdog                                         :  3.0.0 (OK)
zmq >=22.1.0                                     :  25.0.2 (OK)

# Optional:
cython >=0.21                                    :  0.29.34 (OK)
matplotlib >=3.0.0                               :  3.7.1 (OK)
numpy >=1.7                                      :  1.24.2 (OK)
pandas >=1.1.1                                   :  2.0.0 (OK)
scipy >=0.17.0                                   :  1.10.1 (OK)
sympy >=0.7.3                                    :  1.11.1 (OK)

# Spyder plugins:
spyder_terminal.terminalplugin 1.2.2             :  1.2.2 (OK)
@ccordoba12
Copy link
Member

Hey @TradeMark17, thanks for reporting. We'll take a look at it to see what's happening.

@dalthviz, could you check if you can reproduce this problem? According to what @TradeMark17 posted above, you need to create an env with Python 3.10.9 and Pytorch, and try to connect it to our Windows installer.

@dalthviz
Copy link
Member

I was unable to get the same message but creating an env with something like conda create -n torch_py310 -c conda-forge python=3.10.9 pytorch, installing in the env also spyder-kernels, and installing Spyder for the current user in a custom location (D drive under a Spyder folder), showed me initially an error message:

image

Or the console gets stuck showing the loading page

Env details:

# packages in environment at C:\Users\dalth\anaconda3\envs\torch_py310:
#
# Name                    Version                   Build  Channel
asttokens                 2.2.1              pyhd8ed1ab_0    conda-forge
backcall                  0.2.0              pyh9f0ad1d_0    conda-forge
backports                 1.0                pyhd8ed1ab_3    conda-forge
backports.functools_lru_cache 1.6.4              pyhd8ed1ab_0    conda-forge
blas                      1.0                         mkl
bzip2                     1.0.8                h8ffe710_4    conda-forge
ca-certificates           2023.5.7             h56e8100_0    conda-forge
cffi                      1.15.1          py310h628cb3f_3    conda-forge
cloudpickle               2.2.1              pyhd8ed1ab_0    conda-forge
colorama                  0.4.6              pyhd8ed1ab_0    conda-forge
comm                      0.1.3              pyhd8ed1ab_0    conda-forge
debugpy                   1.6.7           py310h00ffb61_0    conda-forge
decorator                 5.1.1              pyhd8ed1ab_0    conda-forge
executing                 1.2.0              pyhd8ed1ab_0    conda-forge
future                    0.18.3             pyhd8ed1ab_0    conda-forge
importlib-metadata        6.6.0              pyha770c72_0    conda-forge
importlib_metadata        6.6.0                hd8ed1ab_0    conda-forge
intel-openmp              2021.4.0          haa95532_3556
ipykernel                 6.23.1             pyh025b116_0    conda-forge
ipython                   8.13.2             pyh08f2357_0    conda-forge
jedi                      0.18.2             pyhd8ed1ab_0    conda-forge
jupyter_client            8.2.0              pyhd8ed1ab_0    conda-forge
jupyter_core              5.3.0           py310h5588dad_0    conda-forge
libblas                   3.9.0              12_win64_mkl    conda-forge
libcblas                  3.9.0              12_win64_mkl    conda-forge
libffi                    3.4.2                h8ffe710_5    conda-forge
libhwloc                  2.9.1                h51c2c0f_0    conda-forge
libiconv                  1.17                 h8ffe710_0    conda-forge
liblapack                 3.9.0              12_win64_mkl    conda-forge
libsodium                 1.0.18               h8d14728_1    conda-forge
libsqlite                 3.42.0               hcfcfb64_0    conda-forge
libuv                     1.44.2               h8ffe710_0    conda-forge
libxml2                   2.10.4               hc3477c8_0    conda-forge
libzlib                   1.2.13               hcfcfb64_4    conda-forge
matplotlib-inline         0.1.6              pyhd8ed1ab_0    conda-forge
mkl                       2021.4.0           h0e2418a_729    conda-forge
mkl-service               2.4.0           py310hcf6e17e_0    conda-forge
nest-asyncio              1.5.6              pyhd8ed1ab_0    conda-forge
ninja                     1.11.1               h91493d7_0    conda-forge
numpy                     1.24.3          py310hd02465a_0    conda-forge
openssl                   1.1.1t               hcfcfb64_0    conda-forge
packaging                 23.1               pyhd8ed1ab_0    conda-forge
parso                     0.8.3              pyhd8ed1ab_0    conda-forge
pickleshare               0.7.5                   py_1003    conda-forge
pip                       23.1.2             pyhd8ed1ab_0    conda-forge
platformdirs              3.5.1              pyhd8ed1ab_0    conda-forge
prompt-toolkit            3.0.38             pyha770c72_0    conda-forge
prompt_toolkit            3.0.38               hd8ed1ab_0    conda-forge
psutil                    5.9.5           py310h8d17308_0    conda-forge
pthreads-win32            2.9.1                hfa6e2cd_3    conda-forge
pure_eval                 0.2.2              pyhd8ed1ab_0    conda-forge
pycparser                 2.21               pyhd8ed1ab_0    conda-forge
pygments                  2.15.1             pyhd8ed1ab_0    conda-forge
python                    3.10.9               h966fe2a_2
python-dateutil           2.8.2              pyhd8ed1ab_0    conda-forge
python_abi                3.10                    2_cp310    conda-forge
pytorch                   1.12.1          cpu_py310h5e1f01c_1
pywin32                   304             py310h00ffb61_2    conda-forge
pyyaml                    6.0             py310h8d17308_5    conda-forge
pyzmq                     25.0.2          py310hcd737a0_0    conda-forge
setuptools                67.7.2             pyhd8ed1ab_0    conda-forge
six                       1.16.0             pyh6c4a22f_0    conda-forge
spyder-kernels            2.4.3           win_pyhd8ed1ab_0    conda-forge
sqlite                    3.42.0               hcfcfb64_0    conda-forge
stack_data                0.6.2              pyhd8ed1ab_0    conda-forge
tbb                       2021.9.0             h91493d7_0    conda-forge
tk                        8.6.12               h8ffe710_0    conda-forge
tornado                   6.3.2           py310h8d17308_0    conda-forge
traitlets                 5.9.0              pyhd8ed1ab_0    conda-forge
typing-extensions         4.5.0                hd8ed1ab_0    conda-forge
typing_extensions         4.5.0              pyha770c72_0    conda-forge
tzdata                    2023c                h71feb2d_0    conda-forge
ucrt                      10.0.22621.0         h57928b3_0    conda-forge
vc                        14.3                hb25d44b_16    conda-forge
vc14_runtime              14.34.31931         h5081d32_16    conda-forge
vs2015_runtime            14.34.31931         hed1258a_16    conda-forge
wcwidth                   0.2.6              pyhd8ed1ab_0    conda-forge
wheel                     0.40.0             pyhd8ed1ab_0    conda-forge
xz                        5.4.2                h8cc25b3_0
yaml                      0.2.5                h8ffe710_2    conda-forge
zeromq                    4.3.4                h0e60522_1    conda-forge
zipp                      3.15.0             pyhd8ed1ab_0    conda-forge
zlib                      1.2.13               hcfcfb64_4    conda-forge

Checked installing Spyder for the current user in the default installation and seems like you can see either a message about the kernel continuously restarting or the loading page too

image

Further checking by creating a conda env with something like conda create -n torch_310 -c conda-forge python pytorch spyder-kernels let me create a console without issues:

image

@TradeMark17 could you share here the link with the steps you followed to install pytorch/torch? Did you followed those steps in you base environment? and also, is possible for you to create an env using a more recent version of Python 3.10 (like Python 3.10.11)?

Let us know!

@TradeMark17
Copy link
Author

Thank you both for your responses! @dalthviz I also got the spyder continuous restarting error. When I connect to the default console the console works but I am unable to use the Torch package. I installed PyTorch (Torch) according to the steps in their installer with this command:

conda install pytorch torchvision torchaudio cpuonly -c pytorch

I think I did it in the base environment? I'm not really sure what environments do. The only time I run terminal commands is when people on GitHub or StackExchange say it will help hahah... I tried copying your conda env code above and I have the same issue.

@ccordoba12
Copy link
Member

Thanks for the extra info @TradeMark17!

@dalthviz, so it seems the problem is that we're failing to show the kernel error message about Spyder-kernels not being installed in the selected env, right?

@dalthviz
Copy link
Member

@dalthviz, so it seems the problem is that we're failing to show the kernel error message about Spyder-kernels not being installed in the selected env, right?

Not sure, in my case the env where the console doesn't start properly has spyder-kernels. From what I remember when I was testing this is that creating a new env with conda-forge packages and installing the latest Python 3.10 version (3.10.11) makes things work, so seems to me like some sort of issue with Python 3.10.9, pytorch and spyder-kernels.

However, seems like @TradeMark17 installed pytorch under is base env so maybe that could be causing troubles when using that env from and standalone installation as the custom interpreter? Maybe spyder-kernels is installed but not the correct minimum version?

Not totally sure what could be happening here, sorry

@ccordoba12
Copy link
Member

From what I remember when I was testing this is that creating a new env with conda-forge packages and installing the latest Python 3.10 version (3.10.11) makes things work

Ok, that's good to know. @TradeMark17, could you check that on your side and let us know if the error is solved for you?

@TradeMark17
Copy link
Author

@ccordoba12 I will try this! How do I make a new env with conda-forge packages?

@ccordoba12
Copy link
Member

ccordoba12 commented Jun 4, 2023

You need to use -c conda-forge in your command above to use the conda-forge channel instead of the pytorch one.

However, it seems that channel doesn't have the torchaudio and cpuonly packages, so I don't know if that's going to work for you. But let us know.

@ccordoba12
Copy link
Member

Closing this as a duplicate of issue #21338, which will be fixed in our next version (5.5.0), to be released at the end of the month.

@ccordoba12 ccordoba12 closed this as not planned Won't fix, can't repro, duplicate, stale Oct 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants