Below seems not to work.
import slicer
import os
# Path to your extension .py file
extension_file = "/path/to/YourExtension.py"
# Check if the extension is already installed
installed_extensions = slicer.app.extensionsManagerModel().installedExtensions()
if any(ext.name == "YourExtension" for ext in installed_extensions):
print("YourExtension is already installed.")
else:
# Install the extension
slicer.app.extensionsManagerModel().installExtension(extension_file)
print("YourExtension has been installed.")
# Enable the extension (optional)
extension_metadata = slicer.app.extensionsManagerModel().retrieveExtensionMetadataByName("YourExtension")
if extension_metadata:
extension_id = extension_metadata["id"]
slicer.app.extensionsManagerModel().setExtensionEnabled(extension_id, True)
print("YourExtension has been enabled.")