# Load packages in a list with the using keyword

**URL:** https://discourse.julialang.org/t/load-packages-in-a-list-with-the-using-keyword/79891
**Category:** New to Julia
**Created:** [April 23, 2022, 12:47pm UTC](https://discourse.julialang.org/t/load-packages-in-a-list-with-the-using-keyword/79891 "2022-04-23T12:47:25Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Ismam](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ismam/32/26140_2.png) [@Ismam](https://discourse.julialang.org/u/Ismam)
#### Post date: [April 23, 2022, 12:47pm UTC](https://discourse.julialang.org/t/load-packages-in-a-list-with-the-using-keyword/79891/1 "2022-04-23T12:47:25Z")

</div>

Is there a way to load multiple packages stored in an array of strings, using the using keyword?

Something like this, except that it works please:  
using [“CSV”, “DataFrames”, “Dates”, “Plots”]

Thank you!

---

<div class="post-metadata">

### Author: ![albheim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/albheim/32/34660_2.png) [@albheim](https://discourse.julialang.org/u/albheim)
#### Post date: [April 23, 2022, 1:25pm UTC](https://discourse.julialang.org/t/load-packages-in-a-list-with-the-using-keyword/79891/2 "2022-04-23T13:25:16Z")

</div>

I don’t think this exists, nothing I have seen at least.

You could easily implement something like it, though the only way I could think of now involves `eval` which is not really considered nice to use. But I know too little of how and why this is to say if it would be bad here. Though if you want it this worked for me when testing at least.

```julia
function importall(pkgs) 
    ex = Expr(:using, map(pkg -> Expr(:(.), Symbol(pkg)), pkgs)...)  
    eval(ex)
end 

pkgs = ["LinearAlgebra", "Statistics"]
importall(pkgs)

```

---

<div class="post-metadata">

### Author: ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)
#### Post date: [April 23, 2022, 2:27pm UTC](https://discourse.julialang.org/t/load-packages-in-a-list-with-the-using-keyword/79891/3 "2022-04-23T14:27:14Z")

</div>

It may also be written as a for loop:

```julia
for pkg in pkgs
    @eval using $(Symbol(pkg))
end

```

---

<div class="post-metadata">

### Author: ![Palli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palli/32/3380_2.png) [@Palli](https://discourse.julialang.org/u/Palli)
#### Post date: [April 23, 2022, 2:43pm UTC](https://discourse.julialang.org/t/load-packages-in-a-list-with-the-using-keyword/79891/4 "2022-04-23T14:43:19Z")

</div>

I’m curious why you want to to that.

---

<div class="post-metadata">

### Author: ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)
#### Post date: [April 23, 2022, 2:45pm UTC](https://discourse.julialang.org/t/load-packages-in-a-list-with-the-using-keyword/79891/5 "2022-04-23T14:45:44Z")

</div>

> [@rafael.guerra](#):
>
> It may also be written as a ~~comprehension~~

What was wrong with the comprehension?

And perhaps better to generalize more:

```julia
for pkg in pkgs
    @eval @ __MODULE__ ,using $(Symbol(pkg))
end

```

which would have it work inside modules as expected.

---

<div class="post-metadata">

### Author: ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)
#### Post date: [April 23, 2022, 2:50pm UTC](https://discourse.julialang.org/t/load-packages-in-a-list-with-the-using-keyword/79891/6 "2022-04-23T14:50:22Z")

</div>

> [@oheil](#):
>
> What was wrong with the comprehension?

I have tried to use the best practice: _if no array is to be returned, use a for loop instead of comprehension_
