[SOLVED] How can I pull the fastai lib version from inside the code

I started to work on a set of notebooks where I practice, and practice, and practice some more.

I would like to version them to know which version of fastai I ran them with. I see we now have tags on github so that is really neat to go back at a later time or whatnot.

I have this at the top of my NB:

Last run on: 2018-02-14 16:32:11.115640
PyTorch version: 0.3.1.post2
fastai version: 0.6

If that wouldn’t be too much of a problem and we could still keep a single source of truth, would it be possible to have version accessible from code when symlinking to the folder as opposed to doing pip install? I know this info is in setup.py and now that I think of it I can just read it from there mhmm…

As it happens an overwhelming amount of time, just typing out a question lead me to the solution :wink:

import re

with open('fastai/../setup.py') as f:
    read_data = f.read()

re.search('version = (\d*.\d*)', read_data).groups(0)[0]

… and we get '0.6'!

1 Like