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 笔记本中导入手电筒


基础教程推荐
- 如何让 python 脚本监听来自另一个脚本的输入 2022-01-01
- Dask.array.套用_沿_轴:由于额外的元素([1]),使用dask.array的每一行作为另一个函数的输入失败 2022-01-01
- 在 Python 中,如果我在一个“with"中返回.块,文件还会关闭吗? 2022-01-01
- 使用PyInstaller后在Windows中打开可执行文件时出错 2022-01-01
- 线程时出现 msgbox 错误,GUI 块 2022-01-01
- 筛选NumPy数组 2022-01-01
- 如何在海运重新绘制中自定义标题和y标签 2022-01-01
- 何时使用 os.name、sys.platform 或 platform.system? 2022-01-01
- Python kivy 入口点 inflateRest2 无法定位 libpng16-16.dll 2022-01-01
- 用于分类数据的跳跃记号标签 2022-01-01