已安装Pytorch,但无法在ubuntu 18.04上运行 [英] Pytorch is installed but is not working on ubuntu 18.04
问题描述
我正在尝试通过ubuntu 18.04上的pip安装Pytorch.我有python 3.6,我的笔记本电脑是HP-Pavilion笔记本电脑15
I am trying to install Pytorch via pip on ubuntu 18.04.I have python 3.6 and my laptop is HP-Pavilion notebook 15
安装似乎是正确的,因为我收到消息:
The installation seems to be right because i get the message:
成功安装收集的软件包:火炬,火炬视觉 已安装Torch-1.3.1 + cpu torchvision-0.4.2 + cpu
Installing collected packages: torch, torchvision Successfully installed torch-1.3.1+cpu torchvision-0.4.2+cpu
我运行验证码,没关系
from __future__ import print_function
import torch
x = torch.rand(5, 3)
print(x)
但是,当我关闭终端或重新启动并尝试运行他的相同代码时,出现错误:
However, when i close the terminal or reboot and try to run he same code i get the error:
回溯(最近通话最近一次):
Traceback (most recent call last):
文件"torch.py",第2行,在 进口火炬
File "torch.py", line 2, in import torch
AttributeError:模块"torch"没有属性"rand"
AttributeError: module 'torch' has no attribute 'rand'
推荐答案
您如何执行python脚本?您正在使用哪个python?也许您是在其他python版本中安装了该软件包?
How are you executing the python script? Which python are you using? Maybe you installed the package in a different python version?
尝试为要使用的python设置别名:
Try to set alias to the python you want to use:
alias python=/usr/local/bin/python3.6
然后pip使用您将一直使用的python别名安装软件包.
Then pip install the package with that python alias you will always be using.
python pip install <package name>
Python现在将使用别名 python将软件包安装在python文件中-转到文件:/usr/local/bin/python3.6
Python now will install the package in the python files with the alias python - heading to files: /usr/local/bin/python3.6
让我知道错误是否仍然存在!
Let me know if the error still occurs!
这篇关于已安装Pytorch,但无法在ubuntu 18.04上运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!