I am using a publicly available Mathematica package on this page and is loaded in Mathematica by the command

<< EccentricIMR`;

How do I unload this package? I don't want to use 'Quit' or 'Exit' since I lose all the definitions.

Why do I want to do this? I have two very similar packages with a lot of functions whose names coincide when both the packages are loaded at once. I plan to unload one before I load the other.


Depending on your definition of "unload", it may be enough to remove the package's contexts from $ContextPath.

The symbols will still exist in your kernel, but you'd only run into them by using their full names including the context.


Easiest and most secure method is restarting the kernel with Exit.

You can also try

names = Join[ Names["EccentricIMR`*"] , Names["EccentricIMR`*`*"];
ClearAll /@ names
Remove /@ names

But there is not guarantee that this removes all symbols. E.g., symbols in deeper hidden contexts are neither cleared nor removed this way. Also Protected symbols cannot be removed this way.

  • 1
    $\begingroup$ Exit and Quit will erase all the definitions. I don't want that. $\endgroup$ – Sashwat Tanay Jul 15 '19 at 1:48

I found a hack. The purpose of unloading the package was to avoid conflicts. There is a way to do that. Every package file begins with the statement of the Context. See here.


Here, 'square' is the context. Since we have two similar packages containing functions with the common names, what we first have to do is to keep the context names different. For example, if the first package file begins with


then the second package must begin differently, say


So now, we have created two different contexts which will help us delineate between the two packages. Let's say there is a function with the common name 'func' in both the packages. Here is how I will use func


The first (second) line invokes the func function from the first (second) package.

  • 7
    $\begingroup$ Erm. Yes, that is the way how contexts work; definitely not a hack. Btw., you missed to tell us that you have control over the package source. $\endgroup$ – Henrik Schumacher Jul 15 '19 at 3:50
  • 5
    $\begingroup$ Sorry but this has nothing to do with 'unloading'. This could be the answer to the question how packages/contexts work. Or did I miss the point? $\endgroup$ – Kuba Jul 15 '19 at 6:39
  • $\begingroup$ Yeah, I did not unload the package. But it serves my purpose. $\endgroup$ – Sashwat Tanay Jul 15 '19 at 7:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.