# Nomad Python Batch Job

**URL:** <https://discuss.hashicorp.com/t/nomad-python-batch-job/18918>\
**Category:** Nomad\
**Created:** [December 15, 2020, 3:12pm UTC](https://discuss.hashicorp.com/t/nomad-python-batch-job/18918 "2020-12-15T15:12:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dusts66](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/dusts66/32/15817_2.png) [@dusts66](https://discuss.hashicorp.com/u/dusts66)\
**Post date:** [December 15, 2020, 3:12pm UTC](https://discuss.hashicorp.com/t/nomad-python-batch-job/18918/1 "2020-12-15T15:12:13Z")

</div>

I have a python batch job that has two tasks. The first task pulls the github code and runs a pip install, and the second task runs the app. How can I find the correct path for the python app to run. Here is my example job config.

```auto
job "example-python" {
  periodic {
    cron = "0 9 * * 1-5"
    prohibit_overlap = true
  }
  datacenters = ["dc1"]

  type = "batch"

  group "app" {
    count = 1

    task "setup" {
      driver = "raw_exec"

      lifecycle {
        hook = "prestart"
      }

      config {
        command = "/usr/bin/pip"
        args = ["install", "-r", "local/repo/requirements.txt"]
      }

      artifact {
        source = "git@github.com:example/daily_quotes.git"
        destination = "local/repo"
        options {
          sshkey = "xxxx"
        }
      }
    }

    task "run" {
      driver = "raw_exec"

      config {
        command = "/usr/bin/python"
        args = ["local/repo/app.py"]
      }

    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![tgross](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/tgross/32/3015_2.png) [@tgross](https://discuss.hashicorp.com/u/tgross)\
**Post date:** [December 15, 2020, 8:44pm UTC](https://discuss.hashicorp.com/t/nomad-python-batch-job/18918/2 "2020-12-15T20:44:32Z")

</div>

Hi @dusts66!

There are two issues here. The first is that if you were to `nomad exec` into the `run` task, you’d see that the Nomad task dir is separate for each task:

```auto
$ nomad alloc exec -task run 49e /bin/sh
# echo $NOMAD_TASK_DIR
/var/nomad/alloc/49e613d4-9d66-d504-f68e-387532f09b1b/run/local

```

The second is that the task dir isn’t found at `/local` for `raw_exec` tasks, but the relative path `local` used in your template and artifact destination is relative to the task working directory .

If you want to want to have a prestart task install software, I’d have it do something like:

```auto
job "example-python" {
  periodic {
    cron = "0 9 * * 1-5"
    prohibit_overlap = true
  }
  datacenters = ["dc1"]

  type = "batch"

  group "app" {
    count = 1

    task "setup" {
      driver = "raw_exec"

      lifecycle {
        hook = "prestart"
      }

      config {
        command = "/bin/sh"
        args = ["$NOMAD_TASK_DIR}/prestart.sh"]
      }

      # you could inline this into the args for the command above,
      # but it's a little nicer to read and change in the future
      # if you do it in a template
      template {
        data = <-EOT
#!/bin/sh
/usr/bin/pip install -r ${NOMAD_TASK_DIR}/repo/requirements.txt
mv ${NOMAD_TASK_DIR}/repo ${NOMAD_ALLOC_DIR}/repo
        EOT

        destination = "local/prestart.sh"
      }

      artifact {
        source = "git@github.com:example/daily_quotes.git"
        destination = "local/repo"
        options {
          sshkey = "xxxx"
        }
      }
    }

    task "run" {
      driver = "raw_exec"

      config {
        command = "/usr/bin/python"
        args = ["${NOMAD_ALLOC_DIR}/repo/app.py"]
      }

    }
  }
}

```
