MacOS conda install fails

I have factory reset my iMac today. Installed latest Anaconda, created env, activated env, followed instructions here.

This is the error message I receive when I try to run any code with torch.

  File "torch.py", line 1, in <module>
    import torch
  File "/Users/reubenschmidt/code/python/nn/cxr_net/torch.py", line 3, in <module>
    x = torch.rand(5,3)
AttributeError: partially initialized module 'torch' has no attribute 'rand' (most likely due to a circular import)

Terminal conda list | grep torch result:

pytorch                   1.4.0                   py3.8_0    pytorch
torchvision               0.5.0                  py38_cpu    pytorch

This issue has been discussed previously here:

Any thoughts would be much appreciated. Cheers.

Hi,

This most likely happens because you have a local file called torch.py. And so when you do import torch, it tries to import that local file instead of the torch library. You should not have a file (or folder) with the same name as a library you use locally to avoid issues :slight_smile:

2 Likes

Thank you so much for your help albanD. That was a really dumb mistake on my behalf!

I owe you one. Cheers.

There are so many names I can have. Why I have to name it as torch.py?!!! Thank you for your questions. This helps me!