M2 icon indicating copy to clipboard operation
M2 copied to clipboard

loadPackage fails for hard to determine reason

Open mikestillman opened this issue 1 year ago • 3 comments

Sometimes, calling loadPackage can fail, saying it cannot be reloaded.

This error occurred in a set of packages I wrote a few years ago. I have boiled it down to its essence:

In A.m2, place the code

newPackage("A", Headline => "A")

In B.m2, place the code

needsPackage "A"
newPackage("B", Headline => "B")

Now after creating these files, try the following code.

elapsedTime installPackage "A"
elapsedTime installPackage "B"
restart
loadPackage "A"

This last line fails, since the package ''A" has been loaded when "B" is being scanned for its newPackage code (I think), and so has already been loaded. This is very hard to determine, as any installed package could do this and cause the package to simply be loaded already... Using needsPackage works fine.

Also, the time to install the package "A" seems to take 4-5 seconds on my machine, which seems quite large. (Same with "B").

mikestillman avatar Jun 16 '24 21:06 mikestillman