spyder-ide / spyder

Official repository for Spyder - The Scientific Python Development Environment
https://www.spyder-ide.org
MIT License
8.33k stars 1.61k forks source link

Spyder crash with Pytorch #16456

Open ma-sadeghi opened 3 years ago

ma-sadeghi commented 3 years ago

Description

What steps will reproduce the problem?

I was playing around w/ numpy and torch libraries that an error message popped up.

Traceback

Exception in comms call get_namespace_view:
  File "/home/amin/mambaforge/lib/python3.9/site-packages/spyder_kernels/comms/commbase.py", line 314, in _comm_message
    buffer = cloudpickle.loads(msg['buffers'][0],
ModuleNotFoundError: No module named 'torch'

Versions

Dependencies


# Mandatory:
atomicwrites >=1.2.0          :  1.4.0 (OK)
chardet >=2.0.0               :  4.0.0 (OK)
cloudpickle >=0.5.0           :  2.0.0 (OK)
cookiecutter >=1.6.0          :  1.7.3 (OK)
diff_match_patch >=20181111   :  20200713 (OK)
intervaltree >=3.0.2          :  3.0.2 (OK)
IPython >=7.6.0               :  7.27.0 (OK)
jedi >=0.17.2;<0.19.0         :  0.18.0 (OK)
jsonschema >=3.2.0            :  3.2.0 (OK)
keyring >=17.0.0              :  23.2.1 (OK)
nbconvert >=4.0               :  6.1.0 (OK)
numpydoc >=0.6.0              :  1.1.0 (OK)
parso >=0.7.0;<0.9.0          :  0.8.2 (OK)
pexpect >=4.4.0               :  4.8.0 (OK)
pickleshare >=0.4             :  0.7.5 (OK)
psutil >=5.3                  :  5.8.0 (OK)
pygments >=2.0                :  2.10.0 (OK)
pylint >=2.5.0;<2.10.0        :  2.9.6 (OK)
pyls_spyder >=0.4.0           :  0.4.0 (OK)
pylsp >=1.2.2;<1.3.0          :  1.2.2 (OK)
pylsp_black >=1.0.0           :  None (OK)
qdarkstyle =3.0.2             :  3.0.2 (OK)
qstylizer >=0.1.10            :  0.2.1 (OK)
qtawesome >=1.0.2             :  1.0.3 (OK)
qtconsole >=5.1.0             :  5.1.1 (OK)
qtpy >=1.5.0                  :  1.11.1 (OK)
rtree >=0.9.7                 :  0.9.7 (OK)
setuptools >=49.6.0           :  49.6.0.post20210108 (OK)
sphinx >=0.6.6                :  4.2.0 (OK)
spyder_kernels >=2.1.1;<2.2.0 :  2.1.1 (OK)
textdistance >=4.2.0          :  4.2.1 (OK)
three_merge >=0.1.1           :  0.1.1 (OK)
watchdog >=0.10.3             :  2.1.5 (OK)
xdg >=0.26                    :  0.27 (OK)
zmq >=17                      :  22.2.1 (OK)

# Optional:
cython >=0.21                 :  None (OK)
matplotlib >=2.0.0            :  None (OK)
numpy >=1.7                   :  None (OK)
pandas >=1.1.1                :  None (OK)
scipy >=0.17.0                :  None (OK)
sympy >=0.7.3                 :  None (OK)
steff456 commented 3 years ago

Hi @ma-sadeghi,

It seems you don't have Pytorch installed in your environment, can you please install it and try again?

ma-sadeghi commented 3 years ago

Hi @steff456, I just checked and I already had it installed. If it helps debugging the issue, I'm using a virtual env, which has torch installed, but Spyder itself is on base env, which doesn't have it installed.

steff456 commented 3 years ago

Did you connect your virtual env as your Python Interpreter?

ma-sadeghi commented 3 years ago

Yes, actually, torch worked fine and I was working w/ it in the console while this happened.

steff456 commented 3 years ago

When you restarted Spyder, do the error persists?

ma-sadeghi commented 3 years ago

No, same error. Here are instructions to reproduce it:

  1. Open Spyder
  2. In IPython Console, run:
    
    Python 3.8.10 | packaged by conda-forge | (default, May 11 2021, 07:01:05)
    Type "copyright", "credits" or "license" for more information.

IPython 7.27.0 -- An enhanced Interactive Python.

In [1]: import torch

In [2]: x = torch.rand(5,5)

3. An error message pops up with the following details:
```bash
Exception in comms call get_namespace_view:
  File "/home/amin/mambaforge/lib/python3.9/site-packages/spyder_kernels/comms/commbase.py", line 314, in _comm_message
    buffer = cloudpickle.loads(msg['buffers'][0],
ModuleNotFoundError: No module named 'torch'

Strangely, this only happens when I assign to variable, it doesn't happen if I just run torch.rand(5,5) without assigning it.

steff456 commented 3 years ago

@ccordoba12 or @impact27 do you know why this may be happening?

impact27 commented 3 years ago

Hi @steff456, I just checked and I already had it installed. If it helps debugging the issue, I'm using a virtual env, which has torch installed, but Spyder itself is on base env, which doesn't have it installed.

So the variable explorer tries to load the torch object but can't because it is not installed in the frontend side. Do you see a crash or just an error?

dalthviz commented 3 years ago

Just in case, @ma-sadeghi checking the option Exclude unsupported data types in the variable explorer options menu prevents the error dialog poping-up? If that is the case maybe this is related with https://github.com/spyder-ide/spyder/issues/16348 and then the error is not just within the installer but when using inside Spyder a custom interpreter with Pytorch

ma-sadeghi commented 3 years ago

@impact27 It's just an error. @dalthviz Checking that option fixed the issue.