Pytorch is installed but is not working on ubuntu 18.04

大兔子大兔子 提交于 2019-12-24 17:11:51

问题


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:

Installing collected packages: torch, torchvision Successfully installed torch-1.3.1+cpu torchvision-0.4.2+cpu

i run the verification code and it is ok

  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):

File "torch.py", line 2, in import torch

AttributeError: module 'torch' has no attribute 'rand'


回答1:


How are you executing the python script? Which python are you using? Maybe you installed the package in a different python version?

Try to set alias to the python you want to use:

alias python=/usr/local/bin/python3.6

Then pip install the package with that python alias you will always be using.

python pip install <package name>

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!




回答2:


Install pytorch using pip through the below command:

pip3 install torch==1.3.1+cpu torchvision==0.4.2+cpu -f https://download.pytorch.org/whl/torch_stable.html

for any reference go through the official website of pytorch.



来源:https://stackoverflow.com/questions/59358141/pytorch-is-installed-but-is-not-working-on-ubuntu-18-04

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!