Remove package from environment in Julia

I am loading packages in the environment with using LIBRARY. Is there a way to remove that package from the environment? something like R’s detach? Thanks

AFAIK, no.


pity… but fair enough. Thanks

May be I am not following, but a package may be removed from an environment by ]rm PACKAGE.

1 Like

Based on the descriptions of detach, I think environment refers to the workspace containing loaded variables and functions. In that case, the answer is no. Unfortunately, you would have to start a new Julia session. Is there a reason that you need to remove the package from the workspace?

Probably to get rid of exported symbols? Or maybe a package carries out piracy, and you don’t want to lose all your work just because you loaded a package mistakenly.

1 Like

sometimes packages have the same function’s names. Specifically I had optim ​ in both Optim and Statistics. Can I solve with ]rm Statistics?

why do you need to “solve” anything? just use



I believe you that you ran into a namespace collision because that happens, but I think your problem must be bigger than this if that was your specific problem because

help?> Statistics.optim
  No documentation found.

  Binding Statistics.optim does not exist.

That is exactly what I wanted to avoid… @tbeason Thanks, I thought that was the problem, I’ll check it out. Still, for general knowledge, if there is a way to import and deport a package it might be good for other occasions. Thanks

Perhaps you may want to import only the functions that you will be using:

using MyPackage: function1, function2

I’m not sure if this will work for you here as I’m not sure if using brings the whole package into the current environment and therefore using X: f1 will bring the required auxiliary functions along with it in order to make f1 work.

I must say, however, that explicit namespace uses such as Optim.optim is not something you should be avoiding. Even in R, you can use double colon :: to do the same as there are some packages that re-export the same function names. Overall it adds to clarity of your code as you know exactly which version of a function is being called.


Ok, that makes sense. Thank you.