I want to use one function from a built in package (specifically CCompilers[] from "CCompilerDriver"). It seems unnecessary to load in the whole package for the rest of my session, how can I do this only temporarily?

Is something like the following sufficient for this?

Needs["CCompilerDriver"];
compilers = CCompilers[];
ClearAll["CCompilerDriver"];


Or is there some kind of preferred or standard method that's more complete? I think I have something in mind which would work a bit like Block

• OK thanks, I can use this to do what I want to. It would also be cool to have an environment like Block which loads a package only temporarily. I don't think the thread you linked answers that question. – Joe May 7 '18 at 11:05
• In short, packages cannot be unloaded. "Unnecessary" does not seem like a good motivation to want to do this. If you explain your specific concerns, perhaps we can suggest a way to address them. So, what do you expect to gain by unloading the package? – Szabolcs May 7 '18 at 13:26
• If you just want to prevent name pollution, then either: 1) remove the package context from $ContextPath when you're done (this does not unload) or 2) prevent adding it to the context path in the first place by loading the package using Block[{$ContextPath}, Needs["SomePackage"]]. If you do this, you will need to use fully qualified names such as CCompileDriverCCompilers[]. ClearAll seems like a bad idea to me, and could cause breakage much more easily than what I suggested. – Szabolcs May 7 '18 at 13:29
• OK thanks Szabolcs, I've decided to go with your solution of 'stop worring about it' – Joe May 8 '18 at 11:09
• You could also use Block[{\$ContextPath}, Needs["CCompilerDriver"]; CCompilerDriverCCompilers[] ]. Just be sure to use Needs and not Get`, to prevent double-loading. – Szabolcs May 8 '18 at 11:44