Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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?

share|improve this question
    
I never looked at the install option before, I've always done it by hand. –  rcollyer Jan 25 '12 at 17:51

2 Answers 2

up vote 11 down vote accepted

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

%appdata%\Mathematica\Applications

(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.

share|improve this answer
    
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. –  István Zachar Jan 25 '12 at 18:34
    
@István Edited, seems possible, but I have no experience with this ... –  Szabolcs Jan 25 '12 at 18:37
1  
@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). –  Szabolcs Jan 25 '12 at 19:03
2  
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. –  Albert Retey Jan 25 '12 at 21:01
    
@Albert Good point, I was not aware of that –  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).

share|improve this answer
    
+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. –  Mr.Wizard Jan 25 '12 at 17:56
2  
Also, packages in the system folder will get lost on upgrade (from e.g. 8.0.1 to 8.0.4) –  Szabolcs Jan 25 '12 at 17:58
1  
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. –  István Zachar Jan 25 '12 at 18:31
2  
@Istvan Well, a lot can get lost when reinstalling Windows. –  Leonid Shifrin Jan 25 '12 at 18:36
1  
@Leonid: Nothing gets lost if kept at a safe place out of the installer's path, preferably on an other drive :) –  István Zachar Jan 25 '12 at 18:47

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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