Skip to main content
DevOps Insightsguides & answers

Linux · troubleshooting

/usr/bin/env: 'python': No such file or directory

A script's first line asks for python, and this system only has python3. Current Ubuntu and Debian do not install a python command. Point the script at python3, or install the package that adds the alias.

Reproduced on Ubuntu 24.04, . Where the text says “reproduced”, the behaviour was run on that version, not taken from documentation.

First published

New to this? Read what is actually happening first, then come back to the steps.

On this page · 8 sections

Before you start

  • The script's first line, and permission to edit it or to install a package.

Run this first

step 1 of 1
command -v python python3

Look for Only a python3 line

Shows which Python commands exist on PATH.

Work out which cause you have

A few questions to narrow the list. Every answer ends in a command that confirms or rules the cause out — this cannot see your cluster, so nothing here is a certainty until you have checked.

Narrow it down

0 answered · nothing is sent anywhere

Does python3 exist here?

Cause space

2 of 2 still possible

  • Only python3 is installedCommon
  • No Python is installed at allOccasional

Nothing ruled out yet. Answer the question above and the branches your answer eliminates will strike through here.

Or diagnose it manually

In this order. The first command usually contains the whole answer.

  1. Step 1

    command -v python python3

    Shows which Python commands exist on PATH.

    Look for Only a python3 line

Every cause, and how to fix it

Ordered by how often each one turns out to be the answer.

Only python3 is installed

Common

The script, a tool's hook or an old build script assumes a python command.

Confirm

head -1 SCRIPT
command -v python python3

#!/usr/bin/env python, and only python3 found

Fix

  • Change the shebang to #!/usr/bin/env python3, or run it as python3 SCRIPT.
  • Where you control the machine or image and many tools expect python: sudo apt install python-is-python3.
  • In a virtual environment, activate it first; it provides python.
sed -i '1s|^#!/usr/bin/env python$|#!/usr/bin/env python3|' SCRIPT

Reproduced on Ubuntu 24.04: changes only a first line that is exactly #!/usr/bin/env python, and the script then ran.

No Python is installed at all

Occasional

Minimal container images and slim CI runners often ship without any Python; env reports the missing program the same way.

Confirm

command -v python3 || echo none

none: there is no python3 either

Fix

  • Install Python in the image or job (on Debian and Ubuntu: apt-get install -y python3), or use an image that includes it.

Understanding it properly

Skip this if you are mid-incident — the working part of the page is above. Worth reading afterwards, because understanding the mechanism is what stops the next one.

In plain terms

The #!/usr/bin/env python line means: find a program called python and run this file with it. There is none, because Python 2 is gone and the distribution names Python 3 python3. The script itself is fine.

Words used on this page

Shebang
The #! first line naming the interpreter for the file.
Exit code 127
The shell's code for a command that could not be found.
What is actually happening

Reproduced on 23 October 2026 on Ubuntu 24.04: a script beginning #!/usr/bin/env python printed /usr/bin/env: 'python': No such file or directory and exited 127. The system had /usr/bin/python3 and no python.

Ubuntu offers python-is-python3, described as symlinks /usr/bin/python to python3; on this server it was available but not installed. It was not installed for this test.

How to tell this is your problem
WhereWhat you see
Running a script directly/usr/bin/env: 'python': No such file or directory
Typing python (Ubuntu's suggestion)Command 'python' not found, did you mean: command 'python3' from deb python3, command 'python' from deb python-is-python3

How to know it is actually fixed

  • The script runs, or python --version answers once the package is installed.

Stopping it happening again

  • Write #!/usr/bin/env python3 in new scripts.
  • In container images, install what your scripts need explicitly rather than relying on the base image's python.

Sources

Behaviour described here is drawn from official documentation. Where a figure could not be confirmed on an official page it is attributed in the text rather than stated as canonical.

Did this get you to an answer?

No text box on purpose — please do not paste production logs anywhere

Something wrong or out of date? Report it