On Desktop, I can install a custom package in the Applications directory under AddOns. This path appears in $Path and loading the package is successful.

On Cloud, I tried to install a package in "Base`Applications`" like I would on Desktop, but the only way loading the package has worked is if I run Prepend[$ContextPath, "Base`Applications`"] at the beginning of a notebook. The path to Base/Applications exists on the $Path.

Can the context be set automatically? Where is one supposed to install a package? Is this a bug?

  • 2
    $\begingroup$ You can install them normally in $UserBaseDirectory/Applications just like in Desktop Mathematica I believe. $\endgroup$ – b3m2a1 May 25 '19 at 19:55
  • $\begingroup$ Does it answer your question? mathematica.stackexchange.com/q/175543/5478? $\endgroup$ – Kuba May 26 '19 at 7:43
  • $\begingroup$ This helps, but it seems there is a bug. I have checked the $Path and it contains the cloud path. I moved the package file to that location, but I have seen inconsistent results unless I run Prepend as mentioned. Even this fails on the mobile app sometimes $\endgroup$ – Dan Kowalczyk May 26 '19 at 16:47
  • $\begingroup$ @DanKowalczyk it is hard to help without a clear description of steps that lead to a problem $\endgroup$ – Kuba Jun 3 '19 at 6:37

I made a mistake by trying to import the context that the file defines, not the file itself. D'oh!

The package I tried to import is defined in a file named $UserBaseDirectory/Applications/Package.m. The context it defines is Package`Main`. I was running Needs["Package`Main`"] because as a newbie I thought imports must refer to the context, however this fails.

I am now able to import successfully by simply specifying the filename as Needs["Package`"]. This works because the $Path contains $UserBaseDirectory/Applications/.

| improve this answer | |
  • 1
    $\begingroup$ You could expand on this giving a proper answer to your original question (basically saying that $UserBaseDirectory works) and then mention what happened to you. $\endgroup$ – b3m2a1 Jun 7 '19 at 17:23
  • $\begingroup$ Thanks for reviewing this and for your suggestion. I added some more details. $\endgroup$ – Dan Kowalczyk Jun 8 '19 at 3:27

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