jupyter notebook配置pytorch
时间: 2023-06-05 17:47:23 浏览: 149
1. 首先需要安装 Jupyter Notebook 和 PyTorch,在终端/命令行中输入以下命令:
```
pip install jupyter
pip install torch torchvision
```
2. 安装完成后,在终端/命令行中输入 jupyter notebook 启动 Jupyter Notebook。
3. 打开 Jupyter Notebook 后,新建一个 notebook 文件。在第一个 code cell 中输入以下代码以检查 PyTorch 是否安装正确:
```
import torch
print(torch.__version__)
```
4. 运行该 code cell,如果显示的是 PyTorch 的版本号,则说明 PyTorch 安装成功。
5. 如果你需要使用 GPU 进行计算,可以在终端中输入
```
pip install torch torchvision torchtext torchaudio -f https://download.pytorch.org/whl/cuXXX/torch_stable.html
```
其中 cuXXX 是你 GPU 的 CUDA 版本,如 cu110,需要改成对应的版本.
然后在代码中使用 torch.cuda 包来使用 GPU 进行计算.
```python
import torch
if torch.cuda.is_available():
device = torch.device("cuda")
print("GPU is available")
else:
device = torch.device("cpu")
print("GPU is not available")
```