събота, 16 януари 2021 г.

How to enable cuda in python with optirun

Today I wanted to try fast.ai notebooks. The require cuda, which obviously wasn't enabled on my python. To do that I had to search with kfind for kernel.json, because of course they weren't in the place they were supposed to be (~/.local/share/jupyter/kernels/) source and also here. I found two json files, so I started with the first one, which was sufficient (it seems).

So to enable Nvidia with optirun, you have to edit: 

~/anaconda3/share/jupyter/kernels/python3/kernel.json 

to add on the first line: 

 "optirun",

so that it becomes:

"argv": [
  "optirun",


The other json I found was this: ~/anaconda3/pkgs/ipykernel-5.1.4-py37h39e3cac_0/share/jupyter/kernels/python3/ but since the first one worked, I didn't edit this one and all is fine so far.

Also, in case you wonder how to enable the cool diagrams in the notebooks, you first have to install pygraphviz, which took some efforts from my side:

sudo equo install pygraphviz

python3.7 -m pip install graphviz --user  

conda install -c alubbock pygraphviz 

 python3.7 -m pip install pygraphviz --user

And then in the notebook, add:

import graphviz
def gv(s): return graphviz.Source('digraph G{ rankdir="LR"' + s + '; }')

and then you get the cool diagrams.