# Simple question about package : why it doesn't work?

My notebook can't load my package and I don't know why.

I called "testons.m" the file containing my package, I wrote inside it the following exemple code :

BeginPackage[ "Package"]

MainFunction::usage =
"MainFunction[ x] computes a simple function."

Begin[ "Private"]

MainFunction[ x_] :=
Module[ {y},
y = x^2;
y + 1
]

End[]

EndPackage[]


I put it in the folder :C:\Users\Me\Dropbox\internship-2017\Mathematica\initialisation

I wrote in my working notebook :

AppendTo[$Path, "C:\\Users\\Me\\Dropbox\\internship-2017\\Mathematica\\initialisation"]  And when I write later in the same notebook : << Package  Mathematica answers me : "Get::noopen: Cannot open Package." I followed the exact instruction written here : https://reference.wolfram.com/workbench/index.jsp?topic=/com.wolfram.eclipse.help/html/tasks/applications/packages.html Where is my mistake ? Thanks • Try using another name for your package, because Package  context already reserved by Mathematica itself. – Shadowray May 24 '17 at 16:52 • I did it but it does'nt solve the problem with another name. Few questions in the same time : Must the name of the package file be the same as the name of the package inside ? If I modify something inside the package file do I have to do a "refresh" in my notebook ? And can the folder names contains space or accents ? – StarBucK May 24 '17 at 16:59 • Also see the third answer from the end here: community.wolfram.com/groups/-/m/t/879149 about "Private" vs "Private" – Kuba May 24 '17 at 18:09 • Did you create the file as a package from the beginning? It seems that a package is more than a notebook with .wl or .m extension - it appears that you must always open the notebook's File menu, select New, and choose Package. – Vito Vanin May 25 '17 at 0:31 • @StarBucK I think you should call your package by its file name, not context name, so in your case <<"Testons" . Package context can be different from its file name, but I think this is not good practice. – Pinti May 25 '17 at 7:25 ## 1 Answer Thanks to the comments above I have solved the problem. I think it would be nice to summarise how to avoid it. First : We have to add the folder where the package is in the$Path variable. This folder can contain spaces in its name without problem.

We have to save a package as a package file in mathematica (.wl in the menu). The package filename cannot contain "_" (maybe other special letters wont work as well).

To ensure that the functions of the package are loaded, its cells has to be put as initialization cells : menu "cell->cell properties->initialization cell".

Next :

The package is called by its filename not by the string between BeginPackage["thestring"] in the packagefile. Do not forget the "", even if we are talking about the filename. For example if the package filename is "test.wl", we have to call it by writing : << test

The package filename and the package name (the thing we write inside the bracket of BeginPackage) can be different.

After each modifications of package file, we have to load again the package to take in account thoose modifications.

• Let's call the package mypack. Especially if you're going to include separate documentation files (always a good idea!), a good practice is to put the mpack.m (or mypack.wl) package file in a subfolder, also named mypack, of your UserBaseDirectory. And then inside that create a Kernel subfolder and in that place an init.m file whose sole contents, as an initialization cell, is: Get["mypackmypack"]. – murray Jan 7 '19 at 14:57