Versioninfo not defined in Main

I was debugging some issues I had using versioninfo() on an HPC, specifically that I would get the following error:

ERROR: UndefVarError: `versioninfo` not defined in `Main`
Suggestion: check for spelling errors or missing imports.
Hint: a global variable of this name may be made accessible by importing InteractiveUtils in the current active module Main
Stacktrace:
 [1] top-level scope
   @ none:1

But to my surprise, I was able to get the same error on my desktop. If I open a REPL and use versioninfo, everything is fine:

julia> versioninfo()
Julia Version 1.11.2
Commit 5e9a32e7af2 (2024-12-01 20:02 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 12 × AMD Ryzen 5 3600 6-Core Processor
  WORD_SIZE: 64
  LLVM: libLLVM-16.0.6 (ORCJIT, znver2)
Threads: 1 default, 0 interactive, 1 GC (on 12 virtual cores)

But if I try and do it using an eval argument from the command line:

username@my-desktop:~$ julia -e "versioninfo()"
ERROR: UndefVarError: `versioninfo` not defined in `Main`
Suggestion: check for spelling errors or missing imports.
Hint: a global variable of this name may be made accessible by importing InteractiveUtils in the current active module Main
Stacktrace:
 [1] top-level scope
   @ none:1

What gives? I imagine that julia -e "code to be evaluated" should be almost exactly the same as evaluating the same code in a REPL. But maybe there’s something fundamentally different about the two that I don’t understand.

It is a function from InteractiveUtils, which is, by default, only loaded if you are in an interactive session:

%julia -e "using InteractiveUtils; versioninfo()"
Julia Version 1.11.2
Commit 5e9a32e7af2 (2024-12-01 20:02 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 20 × 12th Gen Intel(R) Core(TM) i7-12700F
  WORD_SIZE: 64
  LLVM: libLLVM-16.0.6 (ORCJIT, alderlake)
Threads: 1 default, 0 interactive, 1 GC (on 20 virtual cores)
Environment:
  JULIA_PKG_PRESERVE_TIERED_INSTALLED = true
7 Likes

That explains it. Thanks!

1 Like

Did you notice the answer was in the error message you posted?

1 Like

I did not, my bad. I read the first half of the hint, but because I was looking for a missing function, not a variable, I ignored the rest of the hint as irrelevant.