Spyder crashing when importing torch

Viewed 45

I am using a MacBook Pro (MacOS: Monterey) and I'm using Spyder downloaded as the app for MacOS via this page: https://github.com/spyder-ide/spyder/releases. So it is from a standalone installer and I have installed conda via miniconda3.

Everything works fine until I'm trying to install Pytorch. I have installed the package in a virtual environment with the following code snippet: conda install pytorch torchvision -c pytorch. The installation is successful but when I write import torch, I get the following error message and the kernel restarts:

/Applications/Spyder.app/Contents/Resources/lib/python3.9/spyder/plugins/ipythonconsole/scripts/conda-activate.sh: line 18: 98840 Abort trap: 6           

$CONDA_ENV_PYTHON -m spyder_kernels.console -f $SPYDER_KERNEL_SPEC

Fatal Python error: Aborted

Main thread:
Current thread 0x0000000112f1f600 (most recent call first):
  File "<frozen importlib._bootstrap>", line 241 in _call_with_frames_removed
  File "<frozen importlib._bootstrap_external>", line 1176 in create_module
  File "<frozen importlib._bootstrap>", line 571 in module_from_spec
  File "<frozen importlib._bootstrap>", line 674 in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1006 in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1027 in _find_and_load
  File "/Users/andreasaspe/opt/miniconda3/envs/spyder-env/lib/python3.10/site-packages/torch/__init__.py", line 202 in <module>
  File "<frozen importlib._bootstrap>", line 241 in _call_with_frames_removed
  File "<frozen importlib._bootstrap_external>", line 883 in exec_module
  File "<frozen importlib._bootstrap>", line 688 in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1006 in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1027 in _find_and_load
  File "/var/folders/fk/q49x7w9j6t53t4bvkbj_nkdm0000gp/T/ipykernel_98840/4265195184.py", line 1 in <module>


Restarting kernel...

Note: If I activate the virtual environment in the terminal and run a python-script here, then pytorch works absolutely fine. And I have tried a few times that the python-script also suddenly starts running with no problems in the Spyder console. But when I close down Spyder and starts it again, then the issue starts all over and I cannot find a pattern for why it some times works. I don't know if I'm doing anything wrong regarding my virtual environment? I have changed my python interpreter inside of Spyder to be the one in my virtual environment.. Since it works in the terminal and not in the spyder-console I also suspect that it can be something with my spyder-kernel (as the error also suggest). But I can't really figure out how to fix the spyder-kernel.

I have tried to uninstall and install again, installing with pip instead of conda but nothing works. I have searched the internet and for other people it helped to update Spyder to the newest version and making sure that Pytorch is of the newest version as well. It seems like I have the newest editions of everything, though.

Information about Spyder (as standalone installer): Spyder IDE: 5.3.3 Python 3.9.5 64-bit | Qt 5.15.2 | PyQt5 5.15.7 | Darwin 21.5.0

Information about Pytorch package: Version 1.12.1

0 Answers
Related