Problem with module dependencies in Pluto

I created a module, myModule, that requires the Dates and DataFrames packages.
Fwiw, my src directory contains only myModule.jl which looks like:

module myModule
  using DataFrames, Dates
  export myDF
  
  function myDF()
      df = DataFrame(a = [1, 2, 3], b = [4, 5, 6], c = [today(), today() + Day(1), today() + Day(2)])
      return df
  end
end # module myModule

and my Project.toml file looks like

name = "myModule"
uuid = "c3019312-639c-46e1-a276-88058c088531"
authors = ["ADANNENBERG <alex.dannenberg@gmail.com>"]
version = "0.1.0"

[deps]
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"

The command

using myModule

is sufficient for the module to work in the REPL or in VS Code, i.e. sufficient to make the exported function myDF() work fine in the REPL or VS Code.

In Pluto, however, it appears that the ā€œusing DataFrames, Datesā€ line in myModule is not used or recognized. Instead, when Iā€™m in Pluto I have to use the command

using myModule, DataFrames, Dates

in order not to throw an error.

This was a toy example, but itā€™s true for every module Iā€™ve created: In the REPL or VS Code I just have to have a line ā€œusing moduleNameā€ and all the exported functions in the module work fine. But in Pluto ā€œusing moduleNameā€ will bug and tell me that the packages that moduleName depends upon are not found. In Pluto I can only make moduleName work if I have the line ā€œusing moduleName, Dates, DataFramesā€ā€¦

Is this a feature of Pluto, or a sign that Iā€™ve got a problem in myModule that doesnā€™t cause the REPL or VS Code to bug?

1 Like

you might be better off finding the Plutonians on Discord

It might also be worth reading about Plutoā€™s own package management: (šŸ“¦ Packages ā€” Pluto.jl)

Thanks, I will give it a shotā€¦

First thing i usually do in a notebook is

begin
    import Pkg
    Pkg.activate()
    using ā€¦
end

because Iā€™m no good at sharing :joy:

Thanks, that works. Can you explain why in simple terms?

Not really :grinning: Sometimes I just learn the magic spells that work.

Pluto is awesome, but the design is very ā€œprincipledā€, so you either do things the Pluto way or find out how to do things differently.

I set myself up for that one :smiley:

1 Like