labscript_utils.versions.get_version(import_name, project_name=None, import_path=None)[source]

Try very hard to get the version of a package without importing it.

If import_path is not given, first find where it would be imported from, without importing it. Then look for metadata in the same import path with the given project name (note: this is not always the same as the import name, it is the name for example you would ask pip to install). If that is found, return the version info from it. Otherwise look for a file in the package directory, or a __version__ = <version> literal defined in the package source (without executing it).

  • import_name (str) – The module name.

  • project_name (str, optional) – The package name (e.g. the name used when pip installing the package). This must be specified if it does not match the module name.

  • import_path (str, optional) – The path to the folder containing the installed package.


NotImplementedError – Raised if the module name contains a period. Only top-level packages are supported at this time.


The version literal of the package. If the package cannot be found, NotFound is returned. If the version cannot be obtained in the above way, or if the version was found but was None, NoVersionInfo is returned.