由于安装ipykernel时出现问题,我无法在虚拟环境中使用VS Code上的Jupyter笔记本。当我切换到全局环境时,ipykernel可以成功安装并且我可以运行我的笔记本。
如果我创建一个新文件夹,进入该文件夹,运行python3 -m venv venv
,然后运行source venv/bin/activate
,接着运行code .
,然后创建一个.ipynb
文件并尝试在新单元格中执行任何代码,则VS Code会提示我安装ipykernel。因此我这样做了,然后VS Code会显示如下内容:
Running cells with 'Python 3.8.9 ('venv': venv)' requires ipykernel package.
Run the following command to install 'ipykernel' into the Python environment.
Command: '/Users/my.name/Documents/test/venv/bin/python -m pip install ipykernel -U --force-reinstall'
我使用pip install ipykernel命令时遇到了以下错误:
ERROR: Could not build wheels for pyzmq, which is required to install pyproject.toml-based projects
。我正在运行MacBook M1 Pro上的macOS 12.5.1,使用Visual Studio Code版本为1.71.0,并在Python 3.8.9虚拟环境中操作。请问有哪些步骤可以解决这个问题?以下是一些其他看起来有用的错误信息:Building wheels for collected packages: pyzmq
Building wheel for pyzmq (pyproject.toml) ... error
error: subprocess-exited-with-error
× Building wheel for pyzmq (pyproject.toml) did not run successfully.
│ exit code: 1
╰─> [174 lines of output]
Loads of lines saying "copying something -> somewhere" which I've edited out
buildutils/initlibzmq.cpp:10:10: fatal error: 'Python.h' file not found
#include "Python.h"
^~~~~~~~~~
1 error generated.
error: command '/usr/bin/clang++' failed with exit code 1
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for pyzmq
Failed to build pyzmq
ERROR: Could not build wheels for pyzmq, which is required to install pyproject.toml-based projects
pyzmq
的版本上。之前我使用的是Python3.8
,当我切换到Python3.9
时问题就出现了。所以,我指定了最新版本的pyzmq,问题就解决了。 - undefined