Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install new packages for Mathematica?

What is the proper procedure way to install new packages for Mathematica?

In particular, when you download any notebook from MathWorld, you are are given a link to Mathworld packages, which is are zip files with dozens of .m files

Where do they go?

like image 402
Yaroslav Bulatov Avatar asked Jan 09 '11 20:01

Yaroslav Bulatov


3 Answers

To have your packages that you've either downloaded or personally created visible to Mathematica, put them in $UserBaseDirectory/Applications, or $BaseDirectory/Applications if you want them accessible to all users on your system. Alternatively, version 8.0.4 (and likely earlier) has a menu option: File -> Install which will do it for you. The menu option brings up the following dialog

install dialog

install type drop-down displayed

item source drop-down displayed

where the option "Install for this user only (name)" would install it under $UserBaseDirectory and the "for all users" option would install it under $BaseDirectory.

For more information on where Mathematica places everything I would read this tutorial, and look through directory operations functionality.

like image 65
rcollyer Avatar answered Oct 15 '22 01:10

rcollyer


If they are just temporary packages, it is often easier to load them from the current directory, but otherwise moving the files to anywhere on $Path (such as $UserBaseDirectory/Applications as suggested by rcollyer) will work although some directories are autoloaded.

My usual solution is to have

SetDirectory[NotebookDirectory[]]

as more or less the first line in all notebooks. I can then load packages from the notebook directory with Needs["foo"]`. For versioning, you can use the more verbose form of needs:

Needs["foo`","foo-001.m"] 
like image 45
Janus Avatar answered Oct 15 '22 01:10

Janus


Under Windows it is often better to use %AllUsersProfile% directory instead of %UserProfile% for storing additional packages. The following command gives the path to the corresponding directory under Windows:

First@ReadList["!cmd /C echo %AllUsersProfile%", 
   String] <> "\\Application Data\\Mathematica\\Applications"

P.S. I think this and this answers of John Fultz are relevant.

like image 4
Alexey Popkov Avatar answered Oct 15 '22 00:10

Alexey Popkov