Pytorch is installed but is not working on ubuntu 18.04
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'


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 &lt;package name&gt;


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!
