This is always a problem when I distribute my packages to colleagues working on different platforms. I have my packages installed into a private directory and I autoload some of them when Mathematica starts, but since everyone has a different folder hierarchy and different customs on where to put files/what to autoload, this is always a bottleneck. Should non-power-users simply use the menu option: Install...? Can a foolproof script be defined, that - no matter what platform is in use - installs these packages in a way that both the user and both Mathematica (and the code I wrote and distributed) can find it? That is, packages are not added to the system-default package directory. Or would it be better to put packages into the default directory of Mathematica (e.g. C:\Applications\Mathematica 8.0.1\AddOns)? If yes, then which directory should hold them: LegacyPackages, ExtraPackages or Packages?

Further questions:

What if the package that I send consists of multiple packages, in a delicate directory structure? Can the menuitem Install... deal with that?

  • $\begingroup$ I never looked at the install option before, I've always done it by hand. $\endgroup$ – rcollyer Jan 25 '12 at 17:51

I think that the menu item File -> Install... is very convenient, even for power users. The only problem is that there is no uninstall option. However, if the package consists of a single file, upgrading is easy: the old file will be overwritten with the new file.

You can write some simple instructions for users:

  1. Open the .m file you sent them
  2. Choose File -> Install...
  3. Choose Type -> Package, Source -> (the open notebook), Install Name -> SomePackage
  4. Load the package by evaluating <<SomePackage`.

The only thing that can go wrong is that they mistype the install name.

The Install... menu item will put the package into

FileNameJoin[{$UserBaseDirectory, "Applications"}]

which on Windows is


(Press Win-R and type the above to get to that directory.)

When necessary, the package file can be deleted from that directory.

This is the usual way I install and upgrade palettes myself.

Putting packages into the Mathematica installation directory is not really advantageous because they will get lost when Mathematica is upgraded (for example, from 8.0.1 to 8.0.4). Instead they can be put into $BaseDirectory/Application (for all users) or $UserBaseDirectory/Application (for the current user). This is what the Install... menu item does.

It seems that the Install... menu item can deal with multi-file packages too. "Type of Item to Install" should be set to "Applications", "Source" -> "From File..." and the package files need to be inside an archive (.zip file). I have not used this personally, so I have no experience with it (e.g. about what happens on upgrade).

@AlbertRetey noted below that the Wolfram Player Pro does not have this menu item at all. The only way to install packages into it is to do it manually or create a script that does it.

  • $\begingroup$ See edit in original post about multifile packages. Thanks for clearing up what exactly the Install... does. It was sort of a black box up till now. $\endgroup$ – István Zachar Jan 25 '12 at 18:34
  • $\begingroup$ @István Edited, seems possible, but I have no experience with this ... $\endgroup$ – Szabolcs Jan 25 '12 at 18:37
  • 1
    $\begingroup$ @István Thinking about it, for packages it really doesn't make a big difference. For palettes, using Install... is pretty convenient because palettes are commonly generated (they don't come from a file). $\endgroup$ – Szabolcs Jan 25 '12 at 19:03
  • 2
    $\begingroup$ There is another thing that might or might not be a problem: the PlayerPro is missing the File -> Install menu. You will need to write a script that installs as Leonid has suggested if you want to deploy to PlayerPro. $\endgroup$ – Albert Retey Jan 25 '12 at 21:01
  • $\begingroup$ @Albert Good point, I was not aware of that $\endgroup$ – Szabolcs Jan 25 '12 at 21:27

One very simple option: install all packages into

FileNameJoin[{$UserBaseDirectory, "Applications"}]

It is trivial to write a script which will do that, and this is a platform-independent way of specifying a directory which always exists, and where Mathematica will always look for packages.

As an alternative, you can give the user a choice of a directory, and append it to the $Path variable.

I would not recommend putting packages into system folders such as AddOns, for many reasons. One is that there can be many users on the machine with a single installation of Mathematica, and if you put it into a system folder, all of them will experience its presence there, whether they want it or not (and whether you want it or not).

  • $\begingroup$ +1 everything user should be in $UserBaseDirectory for easy management. Copy system files to this directory as needed, duplicating the tree, if you need to modify them. $\endgroup$ – Mr.Wizard Jan 25 '12 at 17:56
  • 2
    $\begingroup$ Also, packages in the system folder will get lost on upgrade (from e.g. 8.0.1 to 8.0.4) $\endgroup$ – Szabolcs Jan 25 '12 at 17:58
  • 1
    $\begingroup$ To all: I can tell you that anything in the $UserBaseDirectory (if left as default) can get lost when reinstalling Windows. Therefore, I have a very strong feeling against putting my stuff into whatever directory the OS offers. $\endgroup$ – István Zachar Jan 25 '12 at 18:31
  • 3
    $\begingroup$ @Istvan Well, a lot can get lost when reinstalling Windows. $\endgroup$ – Leonid Shifrin Jan 25 '12 at 18:36
  • 1
    $\begingroup$ @Leonid: Nothing gets lost if kept at a safe place out of the installer's path, preferably on an other drive :) $\endgroup$ – István Zachar Jan 25 '12 at 18:47

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.