When the program attempt to conduct 'from torch._C import *', it would get stuck

I wanted to conduct the code following
‘from torch._C import *,’
at the first line in my python file,
but when I was doing this, the program would stay there for a long time and do nothing
how can I handle it
thanks!!

Could you describe your setup a bit more, please?
I.e. in particular:

  • how did you install PyTorch
  • what exactly are you trying to import
  • is import torch also taking a long time
  • is this a new issue, was it working before, or always hanging/slow?

Thanks for you reply!
I installed pytorch with the comand recommend like this

conda install pytorch==1.7.1 torchvision==0.8.2 torchaudio==0.7.2 cudatoolkit=10.1 -c pytorch

Actually I did intend to import torch, but it failed, and we found it was the following code

from torch._C import *

in torch’s init() caused this issue. And when I attemped to run a python file test.py which only contains the above code in Xshell using the comand : python3 test.py, it would work with a quite short time.
I hope these imformation can help you!
Thaks again.

Thanks for the update!

Since it’s working fine in Xshell, what’s the setup causing the slow execution/hang and how do these setups differ? It sounds as if your environments might be different (e.g. re you using conda/pip envs?) and one of them might be broken.

1 Like

Yes,you are right!
After I decided to remove my conda env and recreate the env, then reinstall torch, it worked.
I should realize this cause a bit earlier.
Finally, thaks for your reply with your patience.