Convert string to package name

I’m trying to write a section of script that autonomously loads dependencies from a Julia package list.
It is easy to deal with the Pkg.install part with:

for pkg in PKG_LIST
    if !in(pkg,keys(Pkg.installed()))
      print(string("   Installing ",pkg,"...\n"));Pkg.add(pkg)
    end
  end

But when it comes to the using part. The command using receives no string as argument.
There has been a post discussing on how you can call a function from it’s stringed function name - but this method does not work here. When I try with

pkg=Symbol("Random")
using @eval $pkg

Julia returns me

ArgumentError: Package @eval not found in current path:
- Run `import Pkg; Pkg.add("@eval")` to install the @eval package.

Is there any possible solution for this?

julia> pkg=Symbol("Random")
:Random

julia> using @eval $pkg
ERROR: ArgumentError: Package @eval not found in current path:
- Run `Pkg.add("@eval")` to install the @eval package.

Stacktrace:
 [1] require(::Module, ::Symbol) at .\loading.jl:817

julia> @eval using $pkg

julia> Random
Random
2 Likes

Thanks! This solves it :smile:

By the way,

for pkg in PKG_LIST
    if !in(pkg,keys(Pkg.installed()))
        print(string("   Installing ",pkg,"...\n"));Pkg.add(pkg)
    end
end

can be replaced with

Pkg.add(PKG_LIST)