Convert string to package name

question
package
strings

#1

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?


#2
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

#3

Thanks! This solves it :smile:


#4

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)