在 VS Code 中运行 Jupyter,无法从部分初始化的模块“zmq.backend.cython”导入名称“_device”(很可能是由于循环导入)

问题描述 投票:0回答:1

我最近在新服务器上安装了 Miniconda,并尝试使用 VSCode 访问它。 Jupyter 在

base
环境中运行良好,但截图的问题在我创建的新环境中仍然存在。

我尝试过

pip installl ipykernel --upgrade
python3.10 -m pip install ipykernel
。他们都表示环境满意。

我也尝试过

conda install -n diffusion ipykernel --update-deps --force-reinstall

(diffusion) assa8945@ubco-csl-105751:~$ conda install -n diffusion ipykernel --update-deps --force-reinstall
Channels:
 - defaults
 - conda-forge
Platform: linux-64
Collecting package metadata (repodata.json): done
Solving environment: | Channels:
 - defaults
 - conda-forge
Platform: linux-64
Collecting package metadata (repodata.json): done
Solving environment: done
done

## Package Plan ##

  environment location: /home/assa8945/miniconda3/envs/diffusion

  added / updated specs:
    - ipykernel


The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    cyrus-sasl-2.1.28          |       h52b45da_1         237 KB
    gst-plugins-base-1.14.1    |       h6a678d5_1         2.2 MB
    gstreamer-1.14.1           |       h5eee18b_1         1.7 MB
    jpeg-9e                    |       h5eee18b_1         262 KB
    libclang-14.0.6            |default_hc6dbbc7_1         137 KB
    libclang13-14.0.6          |default_he11475f_1         9.8 MB
    libcups-2.4.2              |       h2d74bed_1         4.5 MB
    libjpeg-turbo-2.1.4        |       h166bdaf_0         988 KB  conda-forge
    libllvm14-14.0.6           |       hdb19cb5_3        33.4 MB
    libpq-12.15                |       hdbd6064_1         2.4 MB
    mysql-5.7.24               |       h721c034_2        60.0 MB
    qt-main-5.15.2             |      h53bd1ea_10        53.7 MB
    ------------------------------------------------------------
                                           Total:       169.1 MB

The following NEW packages will be INSTALLED:

  cyrus-sasl         pkgs/main/linux-64::cyrus-sasl-2.1.28-h52b45da_1 
  jpeg               pkgs/main/linux-64::jpeg-9e-h5eee18b_1 
  libllvm14          pkgs/main/linux-64::libllvm14-14.0.6-hdb19cb5_3 
  mysql              pkgs/main/linux-64::mysql-5.7.24-h721c034_2 

The following packages will be UPDATED:

  libcups             conda-forge::libcups-2.3.3-h4637d8d_4 --> pkgs/main::libcups-2.4.2-h2d74bed_1 
  pexpect            conda-forge::pexpect-4.8.0-pyh1a96a4e~ --> pkgs/main::pexpect-4.8.0-pyhd3eb1b0_3 
  ptyprocess         conda-forge::ptyprocess-0.7.0-pyhd3de~ --> pkgs/main::ptyprocess-0.7.0-pyhd3eb1b0_2 
  six                  conda-forge::six-1.16.0-pyh6c4a22f_0 --> pkgs/main::six-1.16.0-pyhd3eb1b0_1 

The following packages will be SUPERSEDED by a higher-priority channel:

  curl                   conda-forge::curl-8.5.0-hca28451_0 --> pkgs/main::curl-8.5.0-hdbd6064_0 
  decorator          conda-forge::decorator-5.1.1-pyhd8ed1~ --> pkgs/main::decorator-5.1.1-pyhd3eb1b0_0 
  gst-plugins-base   conda-forge::gst-plugins-base-1.22.8-~ --> pkgs/main::gst-plugins-base-1.14.1-h6a678d5_1 
  gstreamer          conda-forge::gstreamer-1.22.8-h98fc4e~ --> pkgs/main::gstreamer-1.14.1-h5eee18b_1 
  jupyter_client     conda-forge/noarch::jupyter_client-8.~ --> pkgs/main/linux-64::jupyter_client-8.6.0-py310h06a4308_0 
  krb5                  conda-forge::krb5-1.21.2-h659d440_0 --> pkgs/main::krb5-1.20.1-h143b758_1 
  libclang           conda-forge::libclang-15.0.7-default_~ --> pkgs/main::libclang-14.0.6-default_hc6dbbc7_1 
  libclang13         conda-forge::libclang13-15.0.7-defaul~ --> pkgs/main::libclang13-14.0.6-default_he11475f_1 
  libcurl             conda-forge::libcurl-8.5.0-hca28451_0 --> pkgs/main::libcurl-8.5.0-h251f7ec_0 
  libev                  conda-forge::libev-4.33-hd590300_2 --> pkgs/main::libev-4.33-h7f8727e_1 
  libpq                  conda-forge::libpq-16.1-h33b98f1_7 --> pkgs/main::libpq-12.15-hdbd6064_1 
  libsodium          conda-forge::libsodium-1.0.18-h36c2ea~ --> pkgs/main::libsodium-1.0.18-h7b6447c_0 
  matplotlib-inline  conda-forge/noarch::matplotlib-inline~ --> pkgs/main/linux-64::matplotlib-inline-0.1.6-py310h06a4308_0 
  ncurses               conda-forge::ncurses-6.4-h59595ed_2 --> pkgs/main::ncurses-6.4-h6a678d5_0 
  parso               conda-forge::parso-0.8.3-pyhd8ed1ab_0 --> pkgs/main::parso-0.8.3-pyhd3eb1b0_0 
  patch              conda-forge::patch-2.7.6-h7f98852_1002 --> pkgs/main::patch-2.7.6-h7b6447c_1001 
  pickleshare        conda-forge::pickleshare-0.7.5-py_1003 --> pkgs/main::pickleshare-0.7.5-pyhd3eb1b0_1003 
  pure_eval          conda-forge::pure_eval-0.2.2-pyhd8ed1~ --> pkgs/main::pure_eval-0.2.2-pyhd3eb1b0_0 
  python-dateutil    conda-forge::python-dateutil-2.8.2-py~ --> pkgs/main::python-dateutil-2.8.2-pyhd3eb1b0_0 
  qt-main            conda-forge::qt-main-5.15.8-h450f30e_~ --> pkgs/main::qt-main-5.15.2-h53bd1ea_10 

The following packages will be DOWNGRADED:

  libjpeg-turbo                            3.0.0-hd590300_1 --> 2.1.4-h166bdaf_0 


Proceed ([y]/n)? y


Downloading and Extracting Packages:
                                                                                                                                                                    
Preparing transaction: done                                                                                                                                         
Verifying transaction: done                                                                                                                                         
Executing transaction: done  

参考Jupyter的输出日志,日志一致写出如下错误。

ImportError: cannot import name '_device' from partially initialized module 'zmq.backend.cython' (most likely due to a circular import)... View Jupyter [log](command:jupyter.viewOutput) for further details.
    > Kernel Id = .jvsc74a57bd03ad251f2618a75fe08ceb8f75801f019d4588ed0b65421a0ecd9fe445a6b51d5.~/miniconda3/envs/diffusion/python.~/miniconda3/envs/diffusion/python.-m#ipykernel_launcher
    > Interpreter Id = ~/miniconda3/envs/diffusion/bin/python
    > at ChildProcess.<anonymous> (~/.vscode-server/extensions/ms-toolsai.jupyter-2023.11.1003402403-linux-x64/dist/extension.node.js:259:1973)
    > stdErr = Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "~/miniconda3/envs/diffusion/lib/jvm/languages/python/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "~/miniconda3/envs/diffusion/lib/jvm/languages/python/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "~/miniconda3/envs/diffusion/lib/jvm/languages/python/lib/python3.10/site-packages/ipykernel_launcher.py", line 15, in <module>
    from ipykernel import kernelapp as app
  File "~/miniconda3/envs/diffusion/lib/jvm/languages/python/lib/python3.10/site-packages/ipykernel/__init__.py", line 7, in <module>
    from .connect import *
  File "~/miniconda3/envs/diffusion/lib/jvm/languages/python/lib/python3.10/site-packages/ipykernel/connect.py", line 12, in <module>
    import jupyter_client
  File "~/miniconda3/envs/diffusion/lib/jvm/languages/python/lib/python3.10/site-packages/jupyter_client/__init__.py", line 3, in <module>
    from .asynchronous import AsyncKernelClient
  File "~/miniconda3/envs/diffusion/lib/jvm/languages/python/lib/python3.10/site-packages/jupyter_client/asynchronous/__init__.py", line 1, in <module>
    from .client import AsyncKernelClient  # noqa
  File "~/miniconda3/envs/diffusion/lib/jvm/languages/python/lib/python3.10/site-packages/jupyter_client/asynchronous/client.py", line 8, in <module>
    import zmq.asyncio
  File "~/miniconda3/envs/diffusion/lib/jvm/languages/python/lib/python3.10/site-packages/zmq/__init__.py", line 103, in <module>
    from zmq import backend
  File "~/miniconda3/envs/diffusion/lib/jvm/languages/python/lib/python3.10/site-packages/zmq/backend/__init__.py", line 31, in <module>
    raise original_error from None
  File "~/miniconda3/envs/diffusion/lib/jvm/languages/python/lib/python3.10/site-packages/zmq/backend/__init__.py", line 26, in <module>
    _ns = select_backend(first)
  File "~/miniconda3/envs/diffusion/lib/jvm/languages/python/lib/python3.10/site-packages/zmq/backend/select.py", line 31, in select_backend
    mod = import_module(name)
  File "~/miniconda3/envs/diffusion/lib/jvm/languages/python/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "~/miniconda3/envs/diffusion/lib/jvm/languages/python/lib/python3.10/site-packages/zmq/backend/cython/__init__.py", line 6, in <module>
    from . import (
ImportError: cannot import name '_device' from partially initialized module 'zmq.backend.cython' (most likely due to a circular import)
23:21:42.461 [error] Error in execution (get message for cell) Error: The kernel died. Error: Traceback (most recent call last):

所以我重新安装

pyzmq
出现了一个新的错误:

23:35:04.002 [error] Disposing kernel process due to an error Error: The kernel died. Error: ... View Jupyter [log](command:jupyter.viewOutput) for further details.
    > Kernel Id = .jvsc74a57bd03ad251f2618a75fe08ceb8f75801f019d4588ed0b65421a0ecd9fe445a6b51d5.~/miniconda3/envs/diffusion/python.~/miniconda3/envs/diffusion/python.-m#ipykernel_launcher
    > Interpreter Id = ~/miniconda3/envs/diffusion/bin/python
    > at ChildProcess.<anonymous> (~/.vscode-server/extensions/ms-toolsai.jupyter-2023.11.1003402403-linux-x64/dist/extension.node.js:259:1973)
    > stdErr = 
23:35:04.003 [error] 
23:35:04.003 [info] Dispose Kernel process 1151820.
23:35:04.005 [error] Failed to connect raw kernel session: Error: The kernel died. Error: ... View Jupyter [log](command:jupyter.viewOutput) for further details.
23:35:04.005 [error] Failed to connect raw kernel session: Error: The kernel died. Error: ... View Jupyter [log](command:jupyter.viewOutput) for further details.
23:35:04.006 [warn] Failed to shutdown kernel, .jvsc74a57bd03ad251f2618a75fe08ceb8f75801f019d4588ed0b65421a0ecd9fe445a6b51d5.~/miniconda3/envs/diffusion/python.~/miniconda3/envs/diffusion/python.-m#ipykernel_launcher [TypeError: Cannot read properties of undefined (reading 'dispose')
    at o_.shutdown (~/.vscode-server/extensions/ms-toolsai.jupyter-2023.11.1003402403-linux-x64/dist/extension.node.js:264:15373)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async s_.shutdown (~/.vscode-server/extensions/ms-toolsai.jupyter-2023.11.1003402403-linux-x64/dist/extension.node.js:264:23350)]
23:35:04.008 [warn] Error occurred while trying to start the kernel, options.disableUI=false Error: The kernel died. Error: ... View Jupyter [log](command:jupyter.viewOutput) for further details.
    > Kernel Id = .jvsc74a57bd03ad251f2618a75fe08ceb8f75801f019d4588ed0b65421a0ecd9fe445a6b51d5.~/miniconda3/envs/diffusion/python.~/miniconda3/envs/diffusion/python.-m#ipykernel_launcher
    > Interpreter Id = ~/miniconda3/envs/diffusion/bin/python
    > at ChildProcess.<anonymous> (~/.vscode-server/extensions/ms-toolsai.jupyter-2023.11.1003402403-linux-x64/dist/extension.node.js:259:1973)
    > stdErr = 
23:35:04.008 [warn] Kernel Error, context = start Error: The kernel died. Error: ... View Jupyter [log](command:jupyter.viewOutput) for further details.
    > Kernel Id = .jvsc74a57bd03ad251f2618a75fe08ceb8f75801f019d4588ed0b65421a0ecd9fe445a6b51d5.~/miniconda3/envs/diffusion/python.~/miniconda3/envs/diffusion/python.-m#ipykernel_launcher
    > Interpreter Id = ~/miniconda3/envs/diffusion/bin/python
    > at ChildProcess.<anonymous> (~/.vscode-server/extensions/ms-toolsai.jupyter-2023.11.1003402403-linux-x64/dist/extension.node.js:259:1973)
    > stdErr = 
23:35:04.025 [info] Process Execution: ~/miniconda3/envs/diffusion/bin/python -c "import ipykernel;print('6af208d0-cb9c-427f-b937-ff563e17efdf')"
23:35:10.990 [info] Check & install missing Kernel dependencies for ~/miniconda3/envs/diffusion/bin/python, ui.disabled=false for resource '~/stable_diffusion/test.ipynb'
23:35:11.010 [info] Process Execution: ~/miniconda3/envs/diffusion/bin/python -c "import ipykernel;print('6af208d0-cb9c-427f-b937-ff563e17efdf')"
23:35:21.092 [info] Dispose Kernel '~/stable_diffusion/test.ipynb' associated with '~/stable_diffusion/test.ipynb'
23:35:21.093 [error] Error in execution Error: The kernel died. Error: ... View Jupyter [log](command:jupyter.viewOutput) for further details.
    > Kernel Id = .jvsc74a57bd03ad251f2618a75fe08ceb8f75801f019d4588ed0b65421a0ecd9fe445a6b51d5.~/miniconda3/envs/diffusion/python.~/miniconda3/envs/diffusion/python.-m#ipykernel_launcher
    > Interpreter Id = ~/miniconda3/envs/diffusion/bin/python
    > at ChildProcess.<anonymous> (~/.vscode-server/extensions/ms-toolsai.jupyter-2023.11.1003402403-linux-x64/dist/extension.node.js:259:1973)
    > stdErr = 
23:35:21.094 [error] Error in execution (get message for cell) Error: The kernel died. Error: ... View Jupyter [log](command:jupyter.viewOutput) for further details.
    > Kernel Id = .jvsc74a57bd03ad251f2618a75fe08ceb8f75801f019d4588ed0b65421a0ecd9fe445a6b51d5.~/miniconda3/envs/diffusion/python.~/miniconda3/envs/diffusion/python.-m#ipykernel_launcher
    > Interpreter Id = ~/miniconda3/envs/diffusion/bin/python
    > at ChildProcess.<anonymous> (~/.vscode-server/extensions/ms-toolsai.jupyter-2023.11.1003402403-linux-x64/dist/extension.node.js:259:1973)
    > stdErr = 
23:35:21.116 [info] Process Execution: ~/miniconda3/envs/diffusion/bin/python -c "import ipykernel;print('6af208d0-cb9c-427f-b937-ff563e17efdf')"
23:35:28.561 [info] End cell 0 execution after 0s, completed @ undefined, started @ undefined

python visual-studio-code jupyter-notebook anaconda
1个回答
0
投票

根据这个github问题,您可以通过以下命令重新安装

pyzmq
来解决:

pip uninstall pyzmq
pip install pyzmq
© www.soinside.com 2019 - 2024. All rights reserved.