Module for Internal Dosimetry in Nuclear Medicine

This is a little piece of code that lets you to install any missing package from within the python interpreter itself, just create a file named slicer_python_package_installer.py inside SlicerPlugins folder in your home folder (create if not exists and add it to modules paths). Then add the following

# import pip main
try:
    from pip import main as pipmain
except:
    from pip._internal import main as pipmain
import importlib

def install_and_import(package):
    try:   
        importlib.import_module(package)
    except:
        pipmain(['install', package])
        importlib.import_module(package)
        pass

def install_package(package):
    try:
        importlib.import_module(package)
    except:
        pipmain(['install', package])
        pass

Then in the python interpreter write the following:

from slicer_python_package_installer import *

And voila! you can easily do

install_and_import('joblib')

1 Like