Short version: your script starts with a shell comment, but Prefect’s run_shell_script step isn’t running your text through a shell. It tries to execute each line as a command; the first “command” it sees is “#”, which is not a file or executable — hence [Errno 2] No such file or directory: '#'.
What to change
- Remove the comment line, or
- Explicitly invoke a shell yourself (bash/sh) so comments are handled, or
- Replace the comment with an echo if you want visible context.
Also, if you intend to pull a Prefect Variable, use Jinja to inject it directly; $PREFECT_VAR_* will not be set automatically. If you truly want $VAR expansion, set expand_env_vars: true and provide the env var.
Working examples
1) Simple, no comments, inject Prefect Variable directly
pull:
- prefect.deployments.steps.run_shell_script:
id: install_wheel
script: |
VERSION="{{ prefect.variables.bess_prefect_version }}"
echo "Installing bess_prefect==$VERSION"
pip install "bess_prefect==${VERSION}"
2) Keep comments by invoking a shell explicitly (Linux/macOS)
pull:
- prefect.deployments.steps.run_shell_script:
id: install_wheel
script: |
bash -lc '
# Install bess_prefect wheel from GitHub Releases
VERSION="{{ prefect.variables.bess_prefect_version }}"
echo "Installing bess_prefect==$VERSION"
pip install "bess_prefect==${VERSION}"
'
3) If you really want $VAR expansion (ensure the env var exists)
pull:
- prefect.deployments.steps.run_shell_script:
id: install_wheel
expand_env_vars: true
env:
PREFECT_VAR_bess_prefect_version: "{{ prefect.variables.bess_prefect_version }}"
script: |
echo "Installing bess_prefect using $PREFECT_VAR_bess_prefect_version"
pip install "bess_prefect==$PREFECT_VAR_bess_prefect_version"
Notes
- Jinja in prefect.yaml: use {{ prefect.variables.my_var }} for Prefect Variables. Don’t rely on a magic PREFECT_VAR_* environment variable unless you set it.
- If you need cross-platform support, invoking bash won’t work on Windows without WSL or Git Bash.
Docs, for when you can’t sleep:
- run_shell_script API:
https://docs-3.prefect.io/v3/api-ref/python/prefect-deployments-steps-utility
- prefect.yaml templating and steps:
https://docs-3.prefect.io/v3/how-to-guides/deployments/prefect-yaml
- Prefect Variables:
https://docs-3.prefect.io/v3/concepts/variables
If you share your OS/runner image and whether that version is a Prefect Variable or an env var, I can tailor the exact snippet.