# Automatically install packages used in script

**URL:** <https://discourse.julialang.org/t/automatically-install-packages-used-in-script/102279>\
**Category:** General Usage\
**Created:** [July 31, 2023, 12:21am UTC](https://discourse.julialang.org/t/automatically-install-packages-used-in-script/102279 "2023-07-31T00:21:46Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [July 31, 2023, 12:21am UTC](https://discourse.julialang.org/t/automatically-install-packages-used-in-script/102279/1 "2023-07-31T00:21:46Z")

</div>

For some time now we can do `using Package` and julia will prompt the installation of the package.

Wouldn’t it be nice to have a command-line option that does that, like:

```julia
julia --project -pkginstall=[no(default)/yes/prompt] script.jl

```

?

It feels sort of awkward having to either have a separate script (with `Pkg.add(...)`) or an interactive section to run the script for the first time only.

---

<div class="post-metadata">

**Author:** ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)\
**Post date:** [July 31, 2023, 10:32am UTC](https://discourse.julialang.org/t/automatically-install-packages-used-in-script/102279/2 "2023-07-31T10:32:33Z")

</div>

Nice maybe, but I’d still prefer to ship the script with a manifest to get well-defined versions.

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [July 31, 2023, 10:36am UTC](https://discourse.julialang.org/t/automatically-install-packages-used-in-script/102279/3 "2023-07-31T10:36:02Z")

</div>

I think that’s orhogonal. The automatic installation could have an instantiate option for if there is a manifest file available (and could be the default in that case).

---

<div class="post-metadata">

**Author:** ![j-fu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/j-fu/32/11373_2.png) [@j-fu](https://discourse.julialang.org/u/j-fu)\
**Post date:** [July 31, 2023, 3:14pm UTC](https://discourse.julialang.org/t/automatically-install-packages-used-in-script/102279/4 "2023-07-31T15:14:15Z")

</div>

Couldnt you just store project + manifest as strings in the script like Pluto does ? On start they could be unpacked into ~/.julia/environments and activated.

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [July 31, 2023, 5:02pm UTC](https://discourse.julialang.org/t/automatically-install-packages-used-in-script/102279/5 "2023-07-31T17:02:11Z")

</div>

That could be an interesting feature to have, maybe, but would clutter _a lot_ the script. But would be useful for distributing reproducible scripts.

---

<div class="post-metadata">

**Author:** ![gitboy16](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gitboy16/32/24906_2.png) [@gitboy16](https://discourse.julialang.org/u/gitboy16)\
**Post date:** [August 30, 2023, 8:27am UTC](https://discourse.julialang.org/t/automatically-install-packages-used-in-script/102279/6 "2023-08-30T08:27:22Z")

</div>

I had comparable requirements to yours. See below links.

> [@Using package / install automatically](https://discourse.julialang.org/t/using-package-install-automatically/70896):
>
> Hi, If I do using DataFrames and the package is not install, Julia 1.7 will ask me if I want to install it and I will have to type y or n. Is there a way to skip that step and have Julia installed the package if it is not available? Of course one can write a function that check if the package is installed or not and then install it. I was wondering if there is an option I can pass to using DataFrames that will automatically install the package if not installed? Could that be a feature reque…

> <https://github.com/JuliaLang/Pkg.jl/issues/3027>
>
> As suggested by @KristofferC in the following link:
> https://discourse.julialang….org/t/using-package-install-automatically/70896/5
> I am opening an issue so that maintainers can discuss whether they deem it useful or not to have an option to automatically install a package when using \`using\`. That option would bypass the prompt message asking whether the user wants to install the package or not.
> 
> Just speaking for myself here (i.e. not for other users), but when I use \`using X\`, I will probably answer yes 99% of the time to the question "do you want to install package X".
> 
> That option could be implemented via macro or env variable, I don't really have a strong view on it.
> 
> I just think it is a nice to have option.
> 
> Thank you
