Precompile only available in REPL mode?

I can do

(v1.0) pkg> precompile
Precompiling project...
Precompiling IJulia
[ Info: Recompiling stale cache file /Users/sivapvarma/.julia/compiled/v1.0/IJulia/nfu7T.ji for IJulia [7073ff75-c697-5162-941a-fcdaad2a7d2a]
Precompiling Distributions
[ Info: Precompiling Distributions [31c24e10-a181-5473-b8eb-7969acd0382f]

why can’t I do

julia> import Pkg

julia> Pkg.precompile()
ERROR: MethodError: no method matching precompile()
Closest candidates are:
  precompile(::Type) at essentials.jl:452
  precompile(::Any, ::Tuple) at essentials.jl:448
Stacktrace:
 [1] top-level scope at none:0

There is Pkg.API.precompile(). Everytime someone asks this I suggest making a trivial PR to Pkg, but no one has taken up the task yet. Maybe you can be the one?

3 Likes

I personally really like the string macro.
Which lets you run things julia like in Pkg mode from a script

So

using Pkg: @pkg_str
pkg"precompile"
1 Like

I created at PR. Take a look at PR#1188.

4 Likes