3
$\begingroup$

I want to aoutoload a package at the beginning of a notebook. I set up my directory as written here

How to use the Autoload directory?

So, I have these files:

../Work/MyFile.nb

../Work/Autoload/MyPack/MyPack.m

../Work/Autoload/MyPack/Kernel/init.m.

MyPack.m :

ClearAll["Progetto`*"];  

BeginPackage[ "Progetto`"]

    Prova::usage="Prova[]"

    Begin["`Private`"];

        Prova[]:=5+1;

    End[]

EndPackage[]

init.m:

 Get["MyPack`MyPack`"]

In MyFile.nb, I would like use Prova[], but the output isn't 6 but is Prova[].

Where am I wrong? Am I missing something in init.m?

$\endgroup$
5
  • $\begingroup$ Is Progetto` in $Packages after kernel launch? And in $ContextPath? $\endgroup$
    – Kuba
    Commented May 4, 2017 at 8:41
  • $\begingroup$ @Kuba Progetto isn't a file. Should I rename "Progetto" in "MyPack"? $\endgroup$
    – Ale1794
    Commented May 4, 2017 at 8:45
  • $\begingroup$ I thought that "Progetto" was the name of the Package $\endgroup$
    – Ale1794
    Commented May 4, 2017 at 8:49
  • $\begingroup$ $Packages contains context that were exported so if MyPack was loaded then Progetto` should be there. $\endgroup$
    – Kuba
    Commented May 4, 2017 at 8:50
  • $\begingroup$ @Kuba no, in $Packages there isn't Progetto $\endgroup$
    – Ale1794
    Commented May 4, 2017 at 8:56

1 Answer 1

2
$\begingroup$

I want to aoutoload a package at the beginning of a notebook.

In this case, create an initialization cell in the notebook, and load that package in that cell. Select the cell, and tick Cell menu -> Cell Properties -> Initialization Cell.

"Autoloading" refers to loading something on kernel startup, and is completely independent of notebooks. This is not what you need.

So, I have these files:

../Work/MyFile.nb

../Work/Autoload/MyPack/MyPack.m

The Autoload directory I wrote about in the answer you are linking to is located in $UserBaseDirectory. There is only one* such directory, and it is used on kernel startup. It does not interact with notebooks in any way.

* To be completely accurate, there are a few, but they all live in fixed locations, such as $UserBaseDirectory, $BaseDirectory, $InstallationDirectory/SystemFiles, etc.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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