# Precompile only available in REPL mode?

**URL:** <https://discourse.julialang.org/t/precompile-only-available-in-repl-mode/24115>\
**Category:** General Usage\
**Tags:** pkg\
**Created:** [May 11, 2019, 5:06pm UTC](https://discourse.julialang.org/t/precompile-only-available-in-repl-mode/24115 "2019-05-11T17:06:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![SPV](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/spv/32/2606_2.png) [@SPV](https://discourse.julialang.org/u/SPV)\
**Post date:** [May 11, 2019, 5:06pm UTC](https://discourse.julialang.org/t/precompile-only-available-in-repl-mode/24115/1 "2019-05-11T17:06:33Z")

</div>

I can do

```julia
(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
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

```

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [May 11, 2019, 5:20pm UTC](https://discourse.julialang.org/t/precompile-only-available-in-repl-mode/24115/2 "2019-05-11T17:20:18Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![oxinabox](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oxinabox/32/206603_2.png) [@oxinabox](https://discourse.julialang.org/u/oxinabox)\
**Post date:** [May 11, 2019, 7:18pm UTC](https://discourse.julialang.org/t/precompile-only-available-in-repl-mode/24115/3 "2019-05-11T19:18:03Z")

</div>

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

So

```julia
using Pkg: @pkg_str
pkg"precompile"

```

---

<div class="post-metadata">

**Author:** ![SPV](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/spv/32/2606_2.png) [@SPV](https://discourse.julialang.org/u/SPV)\
**Post date:** [May 11, 2019, 8:05pm UTC](https://discourse.julialang.org/t/precompile-only-available-in-repl-mode/24115/4 "2019-05-11T20:05:28Z")

</div>

I created at PR. Take a look at [PR#1188](https://github.com/JuliaLang/Pkg.jl/pull/1188).
