相关文章推荐
大方的香烟  ·  centos7,Python2.7安装req ...·  1 月前    · 
酷酷的酱牛肉  ·  ModuleNotFoundError: ...·  1 月前    · 
好帅的冲锋衣  ·  ModuleNotFoundError: ...·  4 天前    · 
潇洒的吐司  ·  vue项目打包后,npm run ...·  8 月前    · 
慷慨的抽屉  ·  swift ...·  1 年前    · 
精明的数据线  ·  批处理 - Azure ...·  1 年前    · 

用Python 3.10运行细胞需要安装ipykernel

4 人关注

我刚刚在我的笔记本电脑(Ubuntu 20.04)上安装了Python 3.10。

在VS Code中运行Jupyter笔记本在Python 3.9中可以运行,但在Python 3.10中不行。我得到了错误信息。 Running cells with 'Python 3.10.0 64 bit' requires ipykernel installed or requires an update

Update February 2022

贾利勒-努尔莫哈马迪-希亚拉克给出了一个更完整的答案,现在它是 新接受的答案 .

Update January 2022

这是个愚蠢的错误,我解决了我的问题(见 已接受的答案 ).

Things I tried:

  • Clicking on reinstall, which runs:
  • /usr/bin/python3.10 /home/joris/.vscode/extensions/ms-python.python-2021.10.1365161279/pythonFiles/shell_exec.py /usr/bin/python3.10 -m pip install -U --force-reinstall ipykernel /tmp/tmp-12568krFMIDJVy4jp.log
    
  • Running pip3 install --upgrade ipykernel jupyter notebook pyzmq (from this thread).
  • Edits

  • As asked in the comments, here is the output when I click the "reinstall" button:
  • /usr/bin/python3.10 /home/joris/.vscode/extensions/ms-python.python-2021.10.1365161279/pythonFiles/shell_exec.py /usr/bin/python3.10 -m pip install -U --force-reinstall ipykernel /tmp/tmp-10997AnLZP3B079oV.log
    Executing command in shell >> /usr/bin/python3.10 -m pip install -U --force-reinstall ipykernel
    Traceback (most recent call last):
      File "/usr/lib/python3.10/runpy.py", line 196, in _run_module_as_main
        return _run_code(code, main_globals, None,
      File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
        exec(code, run_globals)
      File "/usr/lib/python3/dist-packages/pip/__main__.py", line 19, in <module>
        sys.exit(_main())
      File "/usr/lib/python3/dist-packages/pip/_internal/cli/main.py", line 73, in main
        command = create_command(cmd_name, isolated=("--isolated" in cmd_args))
      File "/usr/lib/python3/dist-packages/pip/_internal/commands/__init__.py", line 96, in create_command
        module = importlib.import_module(module_path)
      File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
        return _bootstrap._gcd_import(name[level:], package, level)
      File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
      File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
      File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
      File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
      File "<frozen importlib._bootstrap_external>", line 883, in exec_module
      File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
      File "/usr/lib/python3/dist-packages/pip/_internal/commands/install.py", line 24, in <module>
        from pip._internal.cli.req_command import RequirementCommand
      File "/usr/lib/python3/dist-packages/pip/_internal/cli/req_command.py", line 15, in <module>
        from pip._internal.index.package_finder import PackageFinder
      File "/usr/lib/python3/dist-packages/pip/_internal/index/package_finder.py", line 21, in <module>
        from pip._internal.index.collector import parse_links
      File "/usr/lib/python3/dist-packages/pip/_internal/index/collector.py", line 12, in <module>
        from pip._vendor import html5lib, requests
    ImportError: cannot import name 'html5lib' from 'pip._vendor' (/usr/lib/python3/dist-packages/pip/_vendor/__init__.py)
    Traceback (most recent call last):
      File "/home/joris/.vscode/extensions/ms-python.python-2021.10.1365161279/pythonFiles/shell_exec.py", line 26, in <module>
        subprocess.check_call(shell_args, stdout=sys.stdout, stderr=sys.stderr)
      File "/usr/lib/python3.10/subprocess.py", line 369, in check_call
        raise CalledProcessError(retcode, cmd)
    subprocess.CalledProcessError: Command '['/usr/bin/python3.10', '-m', 'pip', 'install', '-U', '--force-reinstall', 'ipykernel']' returned non-zero exit status 1.
    
  • Here is what my _vendor folder contains:
  • joris@joris-N751JK:~$ ls /usr/lib/python3/dist-packages/pip/_vendor/
    __init__.py  __pycache__
    
  • Here is the output of reinstalling pip and checking the _vendor file:
  • joris@joris-N751JK:~$ python3 -m pip install --upgrade --force-reinstall pip
    Defaulting to user installation because normal site-packages is not writeable
    Collecting pip
      Using cached pip-21.3.1-py3-none-any.whl (1.7 MB)
    Installing collected packages: pip
      Attempting uninstall: pip
        Found existing installation: pip 21.3.1
        Uninstalling pip-21.3.1:
          Successfully uninstalled pip-21.3.1
    Successfully installed pip-21.3.1
    joris@joris-N751JK:~$ ls /usr/lib/python3/dist-packages/pip/_vendor
    __init__.py  __pycache__
        
    5 个评论
    重新安装ipykernel的结果是什么?有哪些错误信息?
    @Steven-MSFT,请看我的编辑
    你能在文件夹 _vendor 中找到 html5lib 的包吗?看起来你的pip有一些问题,你可以试着重新安装它吗?
    我添加了我的 _vendor - 文件夹的内容
    你的pip出现了一些问题,你需要重新安装你的pip。你可以看一下你所安装的Python3.9。
    python
    python-3.x
    visual-studio-code
    jupyter-notebook
    python-3.10
    Joris Limonier
    Joris Limonier
    发布于 2021-10-31
    4 个回答
    Jalil Nourmohammadi Khiarak
    Jalil Nourmohammadi Khiarak
    发布于 2022-06-07
    已采纳
    0 人赞同

    我想为此补充一点意见。

    你的解决方案是正确的,但当我在新的Linux上使用它时,它对我不起作用。我做了以下工作来解决这个问题。

    可能是人们在使用以下评论后。

    python3.10 -m pip install ipykernel
    

    会得到 "distutils.util "的错误。所以你应该先安装。

    sudo apt-get install python3.10-distutils
    

    然后,如果你尝试安装,你会得到另一个错误。

    ImportError: cannot import name 'html5lib' from 'pip._vendor' (/usr/lib/python3/dist-packages/pip/_vendor/)

    To solve it you should use:

      curl -sS https://bootstrap.pypa.io/get-pip.py | python3.10
    

    最后,如果你跑了,那就最好了。

     /bin/python3.10 ~/.vscode/extensions/ms-python.python-2022.0.1786462952/pythonFiles/shell_exec.py /bin/python3.10 -m pip install -U notebook /tmp/tmp-5290PWIe78U4HgLu.log
        
    你的回答比较完整,我接受。
    datalifenyc
    datalifenyc
    发布于 2022-06-07
    0 人赞同

    我认为ipykernel与3.10不兼容。

    以下是我在用以下命令安装ipykernel时收到的信息。【替换代码0

    UnsatisfiableError: The following specifications were found
    to be incompatible with the existing python installation in your environment:
    Specifications:
      - ipykernel -> python[version='>=2.7,<2.8.0a0|>=3.6,<3.7.0a0|>=3.7,<3.8.0a0|>=3.8,<3.9.0a0|>=3.5,<3.6.0a0|>=3.9,<3.10.0a0']
    Your python: python=3.10
    

    Solution:

    我建议创建一个虚拟环境 using 锥形瓶或其他图书馆.

    为了让你开始。

  • Install Ana锥形瓶.
  • Enter the following commands. [Note: These are the Windows commands - may vary slightly on Mac and Linux.]
  • # Create virtual environment
    # Use a version of Python that is less than 3.10
    conda create --name your_env_name python<3.10
    # Activate new environment
    conda activate your_env_name
    # Install ipykernel
    conda install -c anaconda ipykernel
    # Add this new environment to your Jupyter Notebook kernel list
    ipython kernel install --name your_env_name --user
    # Windows only: When trying to launch `jupyter notebook`, you may receive a win32api error.
    # The command below fixes that issue.
    conda install -c anaconda pywin32
        
    谢谢。有谁赞成吗?欢迎任何未来的更新
    我将接受这个答案,直到给出一个更坚定的答案。
    python 3.10 ipykernel 之间没有冲突。我从vscode弹出的 Python 3.10 requires ipykernel to be installed 中点击了 Install ,之后Jupyter自动工作。我确实同意使用虚拟环境是最好的做法。我使用了 python3 -m venv .venv
    Joris Limonier
    Joris Limonier
    发布于 2022-06-07
    0 人赞同

    我终于找到了出错的原因。我对Python编码有相当的经验,但在一般的版本处理方面,我还远远不是一个专家。
    这里的问题是, ipykernel 在你安装每一个新的Python版本时都需要重新安装。因此,解决我的问题的方法很简单。

    python3.10 -m pip install ipykernel
        
    gamingflexer
    gamingflexer
    发布于 2022-06-07
    0 人赞同

    MacOs M1

    python -m pip install jupyter notebook -U
    

    使用这个和重新启动VSCode it works.

    如果你看到这个错误,也可以工作

    Failed to start the Kernel.