0

If I try to use cuda on the jetson nano in the terminal:

$ python3

> > > import torch
> > > print(torch.cuda.is_available())
True

But if I start a file with the same content the output is False.

Does anyone have any idea how to fix this?

I've tried:

import os
os.environ["CUDA_VISIBLE_DEVICES"] = "0"

and importing the file in the python terminal. While this makes cuda work, the rest of the application wont work.

I hope to see when I start the file with python3 file.py the output True

talonmies
  • 70,661
  • 34
  • 192
  • 269

1 Answers1

0

It seems that the issue is related to the environment variables not being set correctly when running the file. One solution could be to add the following line to the top of your script to ensure that the environment variable is set before importing torch:

import os
os.environ["CUDA_VISIBLE_DEVICES"] = "0"

This will make sure that CUDA is set to use the first available device (device 0) when the script runs. Another solution could be to use a command like

export CUDA_VISIBLE_DEVICES=0

Then run your python script. This should make sure that the environment variable is set correctly when your script runs.

Additionally, you could also check if the cuda version you are using is compatible with the version of Pytorch you have installed and also check if your jetson nano has a cuda enabled GPU.

kitnj
  • 1