Skip to main content

Packages problems on version 9 under OS X


Using Version 9 on OS X, I've run into some problems with creating packages and accessing them. I've done the following:




  • wrote all the function definitions in a notebook and tested that they all worked;

  • created a package of the definitions.

  • used Install to place the package in the FileNameJoin[{$UserBaseDirectory, "Applications"}] directory;


For good measure I rebooted my computer and restarted Mathematica.


Attempting to load the package gives me nothing, so I simplified everything to see if I'd still have a problem. I made a very simple package:


BeginPackage["testPackage`"]
f::usage = "f[x] returns 2x"
Begin["`Private`"]

f[x_] := 2 x
End[ ]
EndPackage[ ]

I saved and installed it as I described above. Still nothing.


<< testPackage`
Names["testPackage`*"]

{}


I have also tried each of the following:


Get["testPackage`"] (* Doesn't appear to do anything or get any response from Mma *)

Get[FileNameJoin[{$UserBaseDirectory, "Applications", "testPackage`"}]]
$Failed

Needs["testPackage`"]
Needs::nocont: Context testPackage` was not created when Needs was evaluated. >>

Nothing works.



You can see the package installed in the ...Mathematica/Applications directory:


directory


I followed (or at least thought I followed) the recommendations in How to install packages?


I thought doing so would place the package in a path known to the front end.


What have I missed?



Answer



If you're creating a package using a notebook (with AutoGeneratedPackage -> Automatic) you need to write all your code in "Initialization Cells". Everything else is commented out.


Comments