Pytorch install-JetPack4.x , ImportError: cannot import name '_has_torch_function'

Hello everyone,

I’m trying to install PyTorch on a Jetson Xavier. I installed the following wheel using pip:

torch-1.10.0-cp36-cp36m-linux_aarch64.whl

The installation completes successfully, but when I try to import torch in Python, I get the following error: Traceback (most recent call last):
File “”, line 1, in
File “/home/nvidia/torch_env/lib/python3.6/site-packages/torch/init.py”, line 523, in
from ._tensor import Tensor
File “/home/nvidia/torch_env/lib/python3.6/site-packages/torch/_tensor.py”, line 14, in
from torch.overrides import (
File “/home/nvidia/torch_env/lib/python3.6/site-packages/torch/overrides.py”, line 32, in
from torch._C import (
ImportError: cannot import name ‘_has_torch_function’
Has anyone encountered this issue before or knows how to fix it?

Hi,

Did you set up PyTorch with the document below?

Thanks.

I followed the documentation and created the virtual environment using “python3 -m virtualenv -p python3 <chosen_venv_name>” The PyTorch 1.10.0 wheel file I used came from:
https://forums.developer.nvidia.com/t/pytorch-for-jetson/72048

I also tried installing other versions of PyTorch, but they all resulted in the same issue. This problem has been bothering me for a long time.

Hi,

Please try to install it on the Jetson natively without using the virtualenv.

Thanks.

Hi, thank you for your reply. However, installing PyTorch 1.10.0 in the native environment still produces the same issue:
nvidia@nvidia-desktop:~$ python3
Python 3.6.9 (default, Mar 10 2023, 16:46:00)
[GCC 8.4.0] on linux
Type “help”, “copyright”, “credits” or “license”, etc.

import torch
Traceback (most recent call last):
File “”, line 1, in
File “/home/nvidia/.local/lib/python3.6/site-packages/torch/init.py”, line 523, in
from ._tensor import Tensor
File “/home/nvidia/.local/lib/python3.6/site-packages/torch/_tensor.py”, line 14, in
from torch.overrides import (
File “/home/nvidia/.local/lib/python3.6/site-packages/torch/overrides.py”, line 32, in
from torch._C import (
ImportError: cannot import name ‘_has_torch_function’

On my device, only version 1.7.0 works correctly, but this version does not fulfill my needs. I am eager to know how to resolve this issue. Thank you.

For reference, my device is Jetson R32 (release), REVISION: 4.3, with CUDA compilation tools, release 10.2, V10.2.89.

I took your advice and uninstalled the system-level PyTorch using sudo pip3 uninstall torch, then installed a newer version. After that, the import error disappeared. It seems the issue was caused by Python picking up the old _C.so first while trying to load the newer Python files leading to a version mismatch and the _has_torch_function import error. Anyway, I really appreciate your help!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.