How to activate a package in a script?

You can just make a regular old temporary directory to put your environment in. One of Pkg’s many strengths is that it separates the set of installed packages from the active environment. This means creating new environments is virtually free!

You can think of Pkg.add as “make sure these packages are available”. If they are already installed somewhere else, Pkg will know and you don’t have to reinstall them.

#!/usr/bin/env julia
import Pkg

tempdir = mktempdir()
Pkg.activate(tempdir)
Pkg.add(["ArgParse", "Pope"])

using ArgParse, Pope
Pope.dostuff()
2 Likes