Non-Python dependencies in Python environment?

How to add non-Python dependencies (executables) to a Python environment?

EDIT: Actually, see the next post for the actual usecase.

As an example, I have the following files:


  pkgs = import <nixpkgs> { };
in pkgs.python311.withPackages (ps: [


(import ./default.nix).env

import os
os.system("pdflatex --version")

Then, I run the python script but it doesn’t find the executable:

$ nix-shell --pure --run "python"
sh: line 1: pdflatex: command not found

How to get pdflatex into PATH so that it’s found in the Python environment?

Seems that I could make it work by using mkShell but actually my usecase is a bit different…

The actual usecase, sorry for not providing this in the first place:

I have a systemd service in NixOS which runs a Python script. This Python script tries to run pdflatex but fails because it’s not in PATH. The relevant parts from the NixOS config:

  env = pkgs.python311.withPackages (ps: [
    # Some python dependencies here...

    # Non-python dependencies
in { = {
    serviceConfig = {
      ExecStart = "${env}/bin/python -m some_script";

How should I define the environment or run the python script so that pdflatex is found?

You can modify the path of the service, or package the script up (or inline/interpolate if it’s short enough for that to make sense).

Here’s how I run a python script with external dependencies in a systemd service:"picture_copy" = {
    script = "${pkgs.python3}/bin/python3 /home/firecat53/docs/family/scott/src/scripts.git/bin/";
    path = [pkgs.python3 pkgs.rsync pkgs.exiftool];
    serviceConfig = {
      User = "firecat53";

Hope that helps!

1 Like