Within my jupyter notebook, torch.cuda.is_available()
returns True
. But when I run a python script, that same line of code in the python script returns False
. This suggests to me that when I run a python script in my notebook, it does not default to using cuda. Any workaround?
Asked
Active
Viewed 3,272 times
2

Cedric Zoppolo
- 4,271
- 6
- 29
- 59

Baymax Lim
- 39
- 1
- 7
-
2Please include the code as text in the question, not as a link to an image. – mkrieger1 Apr 09 '20 at 09:09
-
1To me it seems that the python you refer to does not have the correct linking to cuda, so you would need to fix that. – Marc Apr 09 '20 at 09:16
-
You may want to check which python is by default on your system. Try `!python --version` to check which version you are using from command line. – Cedric Zoppolo Apr 09 '20 at 09:18
-
And to know which version you are running from Jupiter try `import sys` and then `sys.version`. – Cedric Zoppolo Apr 09 '20 at 09:21
-
1@Marc what do you mean by "correct linking"? How would i link it? – Baymax Lim Apr 09 '20 at 09:32
-
@CedricZoppolo I got Python 3.6.8 – Baymax Lim Apr 09 '20 at 09:32
-
It would be easier I think to go with @CedricZoppolo his strategy and refer to the same python as the one your jupyter is using since it is already working there – Marc Apr 09 '20 at 11:24
-
@Marc and how would i refer to the python that my jupyter is using – Baymax Lim Apr 09 '20 at 11:28
-
On my system that's easy as my jupyter notebook uses python 3.7.6 and to use that one I can use the command "python3" instead of the standard "python" but it depends on your system. What OS are you on? – Marc Apr 09 '20 at 11:39
-
@Marc I'm using a cloud computing service called paperspace. I've tried python3. Same issue. – Baymax Lim Apr 09 '20 at 11:54
1 Answers
2
I used the following:
%run -i test_background-matting_image.py -m real-hand-held -i sample_data/input/ -o sample_data/output/ -tb sample_data/background/0001.png
According to this: %run -i
runs the file in IPython’s namespace instead of an empty one i.e the "same python" as my jupyter notebook.

Baymax Lim
- 39
- 1
- 7