vision
vision copied to clipboard
Jupyter Kernel dies on Import
🐛 Describe the bug
Importing torchvision in a Jupyter Notebook makes the kernel crash. For example, a simple Jupyter notebook such as:
import numpy as np
import matplotlib.pyplot as plt
from PIL import Image
from torchvision import transforms
works until line 3, but when importing from torchvision, the kernel crashes. The jupyter logs in VSCode show:
error 16:11:13.96: Disposing session as kernel process died ExitCode: undefined, Reason: /Users/cornelius/anaconda3/envs/general/lib/python3.10/site-packages/traitlets/traitlets.py:2392: FutureWarning: Supporting extra quotes around strings is deprecated in traitlets 5.0. You can use 'hmac-sha256' instead of '"hmac-sha256"' if you require traitlets >=5.
warn(
/Users/cornelius/anaconda3/envs/general/lib/python3.10/site-packages/traitlets/traitlets.py:2346: FutureWarning: Supporting extra quotes around Bytes is deprecated in traitlets 5.0. Use '9d320bd6-ee17-41f0-93dd-660ce9773e10' instead of 'b"9d320bd6-ee17-41f0-93dd-660ce9773e10"'.
warn(
error 16:11:13.96: Raw kernel process exited code: undefined
I am aware of #5953 but reinstalling the environment didnt help.
Versions
MacOS: 12.5 (Intel)
Conda:
# Name Version Build Channel
anyio 3.6.1 pypi_0 pypi
appnope 0.1.3 pypi_0 pypi
argon2-cffi 21.3.0 pypi_0 pypi
argon2-cffi-bindings 21.2.0 pypi_0 pypi
asttokens 2.0.8 pypi_0 pypi
attrs 22.1.0 pypi_0 pypi
babel 2.10.3 pypi_0 pypi
backcall 0.2.0 pypi_0 pypi
beautifulsoup4 4.11.1 pypi_0 pypi
blas 1.0 mkl
bleach 5.0.1 pypi_0 pypi
brotlipy 0.7.0 py310hca72f7f_1002
bzip2 1.0.8 h1de35cc_0
ca-certificates 2022.07.19 hecd8cb5_0
certifi 2022.6.15 py310hecd8cb5_0
cffi 1.15.1 py310hc55c11b_0
charset-normalizer 2.0.4 pyhd3eb1b0_0
cryptography 37.0.1 py310hf6deb26_0
cycler 0.11.0 pypi_0 pypi
debugpy 1.6.3 pypi_0 pypi
decorator 5.1.1 pypi_0 pypi
defusedxml 0.7.1 pypi_0 pypi
entrypoints 0.4 pypi_0 pypi
executing 0.10.0 pypi_0 pypi
fastjsonschema 2.16.1 pypi_0 pypi
ffmpeg 4.3 h0a44026_0 pytorch
fonttools 4.36.0 pypi_0 pypi
freetype 2.11.0 hd8bbffd_0
gettext 0.21.0 h7535e17_0
giflib 5.2.1 haf1e3a3_0
gmp 6.2.1 he9d5cce_3
gnutls 3.6.15 hed9c0bf_0
icu 58.2 h0a44026_3
idna 3.3 pyhd3eb1b0_0
intel-openmp 2021.4.0 hecd8cb5_3538
ipykernel 6.15.1 pypi_0 pypi
ipython 8.4.0 pypi_0 pypi
ipython-genutils 0.2.0 pypi_0 pypi
jedi 0.18.1 pypi_0 pypi
jinja2 3.1.2 pypi_0 pypi
jpeg 9e hca72f7f_0
json5 0.9.10 pypi_0 pypi
jsonschema 4.14.0 pypi_0 pypi
jupyter-client 7.3.4 pypi_0 pypi
jupyter-core 4.11.1 pypi_0 pypi
jupyter-server 1.18.1 pypi_0 pypi
jupyterlab 3.4.5 pypi_0 pypi
jupyterlab-pygments 0.2.2 pypi_0 pypi
jupyterlab-server 2.15.0 pypi_0 pypi
kiwisolver 1.4.4 pypi_0 pypi
lame 3.100 h1de35cc_0
lcms2 2.12 hf1fd2bf_0
lerc 3.0 he9d5cce_0
libcxx 12.0.0 h2f01273_0
libdeflate 1.8 h9ed2024_5
libffi 3.3 hb1e8313_2
libiconv 1.16 hca72f7f_2
libidn2 2.3.2 h9ed2024_0
libpng 1.6.37 ha441bb4_0
libtasn1 4.16.0 h9ed2024_0
libtiff 4.4.0 h2ef1027_0
libunistring 0.9.10 h9ed2024_0
libwebp 1.2.2 h56c3ce4_0
libwebp-base 1.2.2 hca72f7f_0
libxml2 2.9.14 hbf8cd5e_0
llvm-openmp 12.0.0 h0dcd299_1
lxml 4.9.1 pypi_0 pypi
lz4-c 1.9.3 h23ab428_1
markupsafe 2.1.1 pypi_0 pypi
matplotlib 3.5.3 pypi_0 pypi
matplotlib-inline 0.1.6 pypi_0 pypi
mistune 2.0.4 pypi_0 pypi
mkl 2021.4.0 hecd8cb5_637
mkl-service 2.4.0 py310hca72f7f_0
mkl_fft 1.3.1 py310hf879493_0
mkl_random 1.2.2 py310hc081a56_0
nbclassic 0.4.3 pypi_0 pypi
nbclient 0.6.6 pypi_0 pypi
nbconvert 7.0.0 pypi_0 pypi
nbformat 5.4.0 pypi_0 pypi
ncurses 6.3 hca72f7f_3
nest-asyncio 1.5.5 pypi_0 pypi
nettle 3.7.3 h230ac6f_1
notebook 6.4.12 pypi_0 pypi
notebook-shim 0.1.0 pypi_0 pypi
numpy 1.23.1 py310hdcd3fac_0
numpy-base 1.23.1 py310hfd2de13_0
openh264 2.1.1 h8346a28_0
openssl 1.1.1q hca72f7f_0
packaging 21.3 pypi_0 pypi
pandocfilters 1.5.0 pypi_0 pypi
parso 0.8.3 pypi_0 pypi
pexpect 4.8.0 pypi_0 pypi
pickleshare 0.7.5 pypi_0 pypi
pillow 9.2.0 py310hde71d04_1
pip 22.1.2 py310hecd8cb5_0
prometheus-client 0.14.1 pypi_0 pypi
prompt-toolkit 3.0.30 pypi_0 pypi
psutil 5.9.1 pypi_0 pypi
ptyprocess 0.7.0 pypi_0 pypi
pure-eval 0.2.2 pypi_0 pypi
pycparser 2.21 pyhd3eb1b0_0
pygments 2.13.0 pypi_0 pypi
pyopenssl 22.0.0 pyhd3eb1b0_0
pyparsing 3.0.9 pypi_0 pypi
pyrsistent 0.18.1 pypi_0 pypi
pysocks 1.7.1 py310hecd8cb5_0
python 3.10.4 hdfd78df_0
python-dateutil 2.8.2 pypi_0 pypi
pytorch 1.12.1 py3.10_0 pytorch
pytz 2022.2.1 pypi_0 pypi
pyzmq 23.2.1 pypi_0 pypi
readline 8.1.2 hca72f7f_1
requests 2.28.1 py310hecd8cb5_0
send2trash 1.8.0 pypi_0 pypi
setuptools 61.2.0 py310hecd8cb5_0
six 1.16.0 pyhd3eb1b0_1
sniffio 1.2.0 pypi_0 pypi
soupsieve 2.3.2.post1 pypi_0 pypi
sqlite 3.39.2 h707629a_0
stack-data 0.4.0 pypi_0 pypi
terminado 0.15.0 pypi_0 pypi
tinycss2 1.1.1 pypi_0 pypi
tk 8.6.12 h5d9f67b_0
torchaudio 0.12.1 py310_cpu pytorch
torchvision 0.13.1 py310_cpu pytorch
tornado 6.2 pypi_0 pypi
traitlets 5.3.0 pypi_0 pypi
typing_extensions 4.3.0 py310hecd8cb5_0
tzdata 2022a hda174b7_0
urllib3 1.26.11 py310hecd8cb5_0
wcwidth 0.2.5 pypi_0 pypi
webencodings 0.5.1 pypi_0 pypi
websocket-client 1.3.3 pypi_0 pypi
wheel 0.37.1 pyhd3eb1b0_0
xz 5.2.5 hca72f7f_1
zlib 1.2.12 h4dc903c_2
zstd 1.5.2 hcb37349_0
Hi @cemde , do you mind reproducing the code outside of a notebook to see if it still fails?
The error seems to come from traitlets - try uninstalling it maybe?
reproducing the code outside of a notebook to see if it still fails
You can do this by running the following in your VSCode terminal
python -c 'import torchvision'
If that fails, post the message here. If not, try
python -c 'import numpy, matplotlib.pyplot, PIL, torchvision'
If that also does not fail, the problem is most likely not related to torchvision.
@pmeier I tied that. The issue is indeed a little different than I thought it was.
In Jupyter notebook and command line:
import torchvision
import numpy as np
works fine while
import numpy as np
import torchvision
results in an error (copied from command line):
OMP: Error #15: Initializing libiomp5.dylib, but found libomp.dylib already initialized.
OMP: Hint This means that multiple copies of the OpenMP runtime have been linked into the program. That is dangerous, since it can degrade performance or cause incorrect results. The best thing to do is to ensure that only a single OpenMP runtime is linked into the process, e.g. by avoiding static linking of the OpenMP runtime in any library. As an unsafe, unsupported, undocumented workaround you can set the environment variable KMP_DUPLICATE_LIB_OK=TRUE to allow the program to continue to execute, but that may cause crashes or silently produce incorrect results. For more information, please see http://www.intel.com/software/products/support/.
I was not precise enough in my previous testing. This seems to be an issue of the MKL library, which is not needed on MacOS. But it is odd that the order of import matters in generating the error.
I suspect this is the same as https://github.com/pytorch/pytorch/issues/78490 CC @atalman