Setup an environment from a shell script

I’m hoping to run some simulations from a shell script. The structure is something like:

parent
  \__ Manifest.toml
  \__ Project.toml
  \__dir
    \__ sim.sh
    \__ env.jl
    \__ simulate.jl

where sim.sh contains

#!/bin/sh
julia simulate.jl

simulate.jl contains

include("env.jl")
println("...now running simulations...")

and env.jl contains

using Pkg
Pkg.activate("../.")
Pkg.instantiate()

to pull from Manifest/Project files I have in parent/. However, when I run $ ./sim.sh, I get the following error:

ERROR: LoadError: ArgumentError: Module Pkg not found in current path.
Run `Pkg.add("Pkg")` to install the Pkg package.
Stacktrace:
 [1] _require(::Symbol) at ./loading.jl:428
 [2] require(::Symbol) at ./loading.jl:398
 [3] include_from_node1(::String) at ./loading.jl:569
 [4] include(::String) at ./sysimg.jl:14
 [5] process_options(::Base.JLOptions) at ./client.jl:305
 [6] _start() at ./client.jl:371

Am I doing something wrong??


Here’s my version info:

Julia Version 1.1.0
Commit 80516ca202 (2019-01-21 21:24 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin14.5.0)
  CPU: Intel(R) Core(TM) i7-7820HQ CPU @ 2.90GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.1 (ORCJIT, skylake)
Environment:
  JULIA_LOAD_PATH = ...

Ah, I just need to call julia from $JULIA_BINDIR/julia in the shell script and make sure the shebang references the current environment #!/usr/bin/env sh

@jacob_roth It is very worthwhile documenting this. You are running the simulation in a batch system such as Slurm or PBS? There are differences between interactive and non-interactive login shells.
I think you have come across a situation where the non-interactive shell is different.

I don’t need to see the output, which might contain proprietary information. Howwer could you submit a script which simply runs the env command and similary run env at the terminal, then do a diff of the results?

Of course, I may be wrong here.

@johnh: I think I was just using the “wrong” version of Julia. My default path wasn’t properly set up :slight_smile: