void (Module module) { ApplicationManager.getApplication().runWriteAction(() -> { final ModuleRootManager rootManager = ModuleRootManager.getInstance(module); final ModifiableRootModel model = rootManager.getModifiableModel(); // Just remove all old facet libraries for (OrderEntry entry : model.getOrderEntries()) { if (entry instanceof LibraryOrderEntry) { final Library library = ((LibraryOrderEntry)entry).getLibrary(); if (library != null) { final String libraryName = library.getName(); if (libraryName!=null && libraryName.endsWith(PYTHON_FACET_LIBRARY_NAME_SUFFIX)) { model.removeOrderEntry(entry); //PyBuiltinCache.clearInstanceCache(); } } } } model.commit(); }); }