Can#39;t import torch in jupyter notebook(无法在 jupyter 笔记本中导入手电筒)
问题描述
系统:macOS 10.13.6蟒蛇:3.7蟒蛇3
System: macOS 10.13.6 Python: 3.7 Anaconda3
在 jupyter notebook 中 import torch 时遇到问题.
I have trouble when import torch in jupyter notebook.
ModuleNotFoundError: No module named 'torch'
这是我安装pytorch的方法:
Here is how I install pytorch:
conda install pytorch torchvision -c pytorch
我已经检查了 PyTorch 是否安装在我的 anaconda 环境中:
I've checked PyTorch is installed in my anaconda environment:
当我在终端中命令 python3 和 import torch 时,它可以工作.但不适用于 jupyter notebook
When I command python3 in my terminal and import torch, it works. But not work in jupyter notebook
我试过了:
conda update conda
conda install mkl=2018
但还是一样的错误.
谁能帮我解决这个问题?谢谢!!
Can anyone help me with this? Thanks!!
推荐答案
除了 pytorch 之外,您还必须在激活的 conda 环境中安装 jupyter.安装步骤如下:
You have to install jupyter in addition to pytorch inside your activated conda env. Here is installation steps:
例如:pytorch_p37 和 python 3.7:
user@pc:~$ conda create -n pytorch_p37 python=3.7
2.激活它
user@pc:~$ conda activate pytorch_p37
或使用(对于较旧的 conda 版本):
Or with (for older conda versions):
user@pc:~$ source activate pytorch_p37
现在你应该在 shell 提示前看到 (pytorch_p37):
Now you should see (pytorch_p37) before your shell prompt:
(pytorch_p37) user@pc:~$
3.转到 PyTorch 网站 并通过 conda 选择合适的安装命令.例如,在你的 shell 中运行它
3. Go to PyTorch website and choose appropriate installation command via conda. Run it in your shell, for example
(pytorch_p37) user@pc:~$ conda install pytorch torchvision -c pytorch
4.在激活的环境中也安装 jupyter
(pytorch_p37) user@pc:~$ conda install jupyter
5.验证安装
(pytorch_p37) user@pc:~$ conda list
# packages in environment at /home/user/anaconda3/envs/pytorch_p37:
#
# Name
...
jupyter 1.0.0
jupyter_client 5.3.1
jupyter_console 6.0.0
jupyter_core 4.5.0
...
python 3.7.4
pytorch 1.2.0
...
6.运行 jupyter
(pytorch_p37) user@pc:~$ jupyter notebook
这篇关于无法在 jupyter 笔记本中导入手电筒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:无法在 jupyter 笔记本中导入手电筒
基础教程推荐
- 在同一图形上绘制Bokeh的烛台和音量条 2022-01-01
- PANDA VALUE_COUNTS包含GROUP BY之前的所有值 2022-01-01
- 使用大型矩阵时禁止 Pycharm 输出中的自动换行符 2022-01-01
- Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙? 2022-01-01
- 修改列表中的数据帧不起作用 2022-01-01
- 在Python中从Azure BLOB存储中读取文件 2022-01-01
- 求两个直方图的卷积 2022-01-01
- 包装空间模型 2022-01-01
- PermissionError: pip 从 8.1.1 升级到 8.1.2 2022-01-01
- 无法导入 Pytorch [WinError 126] 找不到指定的模块 2022-01-01
