# Use Package (Add if Needed; Using)

**URL:** <https://discourse.julialang.org/t/use-package-add-if-needed-using/8004>\
**Category:** General Usage\
**Created:** [December 26, 2017, 7:19pm UTC](https://discourse.julialang.org/t/use-package-add-if-needed-using/8004 "2017-12-26T19:19:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ivo\_welch](https://avatars.discourse-cdn.com/v4/letter/i/d2c977/32.png) [@ivo\_welch](https://discourse.julialang.org/u/ivo_welch)\
**Post date:** [December 26, 2017, 7:19pm UTC](https://discourse.julialang.org/t/use-package-add-if-needed-using/8004/1 "2017-12-26T19:19:54Z")

</div>

Is it possible to define a function that tests if a package has been installed already, installs it if not yet so, and then invokes using. something like

`use(name) = try Pkg.installed(name) catch Pkg.add(name) end; using name`

This fails for multiple reasons. It would be even better if this could be a statement rather than a function call, so that

`use DataFrames;`

would simply work.

Advice appreciated. And apologies: I will have a lot of questions over the next 1-3 weeks, because I plan to use Julia as a first-class language in my MFE class at UCLA. Wish me luck! I am putting together a cookbook at [http://julia.cookbook.tips](http://julia.cookbook.tips), hopefully understandable in a week or two…

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [December 26, 2017, 7:34pm UTC](https://discourse.julialang.org/t/use-package-add-if-needed-using/8004/2 "2017-12-26T19:34:53Z")

</div>

In Pkg3 (the new Julia package manager) it will work like:

[![](https://global.discourse-cdn.com/julialang/original/3X/f/6/f6040bd9236820911f24be61df270529f50cd300.jpeg "autoinstall") ](https://www.youtube.com/watch?v=Spql1JIwyns)

you can also set it to automatically install without querying.
