Skip to content

Instantly share code, notes, and snippets.

@vincentAgnus
Created March 22, 2023 16:57
Show Gist options
  • Save vincentAgnus/713ca4865eedb74ccdc31d01f1727bf8 to your computer and use it in GitHub Desktop.
Save vincentAgnus/713ca4865eedb74ccdc31d01f1727bf8 to your computer and use it in GitHub Desktop.
Get module/lib version of your env
from importlib.metadata import PackageNotFoundError
from importlib.metadata import version as get_module_version
import subprocess
import os
python_libs ="""
torch
tensorflow
tensorboard
numpy
pandas
scikit-image
scikit-learn
seaborn
simpleitk
tensorboard
torchvision
yaml
imgaug
yacs
yaml
pydicom
tqdm
sacred
cv2
"""
python_libs = python_libs.split()
#print(python_libs)
versions = dict()
for module in python_libs:
try:
versions[module] = get_module_version(module)
except PackageNotFoundError:
versions[module] = 'NOT FOUND'
#cuda version
try:
import torch
assert(torch.cuda.is_available())
versions["cuda"] = torch.version.cuda
except:
#code for second chance with tf ?
try:
versions["cuda"] = "NOTFOUND"
#out = subprocess.check_output(["nvcc","--version"],shell=True, env=None)
#proc = subprocess.Popen("nvcc --version",stdout=subprocess.PIPE,shell=True)
#(out, err) = proc.communicate()
#print(out)
except Exception as e:
#
print(e)
versions["cuda"] = "NOTFOUND"
try:
import torch
assert(torch.backends.cudnn.is_available())
versions["cudnn"] = torch.backends.cudnn.version()
except:
versions["cudnn"] = "NOTFOUND"
for module, version in versions.items():
print(f"{module:<16}{version}")
@vincentAgnus
Copy link
Author

example of output:

torch           1.13.0
tensorflow      NOT FOUND
tensorboard     NOT FOUND
numpy           1.23.4
pandas          1.4.3
scikit-image    NOT FOUND
scikit-learn    NOT FOUND
seaborn         0.11.2
simpleitk       NOT FOUND
torchvision     0.14.0
yaml            NOT FOUND
imgaug          NOT FOUND
yacs            NOT FOUND
pydicom         NOT FOUND
tqdm            NOT FOUND
sacred          NOT FOUND
cv2             NOT FOUND
cuda            11.7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment