youtube-dl: /usr/bin/env: ‘python’: No such file or directory

Checklist

  • I’m reporting a broken site support issue
  • I’ve verified that I’m running youtube-dl version 2021.06.06
  • I’ve checked that all provided URLs are alive and playable in a browser
  • I’ve checked that all URLs and arguments with special characters are properly quoted or escaped
  • I’ve searched the bugtracker for similar bug reports including closed ones
  • I’ve read bugs section in FAQ

Verbose log

yoones:~$ whereis youtube-dl
youtube-dl: /usr/local/bin/youtube-dl
yoones:~$ youtube-dl
/usr/bin/env: ‘python’: No such file or directory

Description

OS: Debian 11.1

I have the following binaries installed:

  • python2.7
  • python3
  • python3.9

The shebang of youtube-dl (#!/usr/bin/env python) does not work in this context since there is no executable file called python.

Suggested solution:

Have a shell script that acts as a launcher. This script could for instance embed a list of known python interpreters (python, python2.7, python3, …) and use the first of the list that is present on the host.

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Comments: 22 (7 by maintainers)

Most upvoted comments

For the moment, install the python-is-python3 package. Or sudo ln /usr/bin/python3 /usr/local/bin/python.

Debian decided that there shouldn’t be a python command by default, perhaps to flush out Py 2 dependencies. Apparently the yt-dl Debian 11+ package would be responsible for patching the shebang(s).

For the self-extracting version, it would be necessary to identify what approach other distros are taking. Perhaps /usr/bin/python3 should be the new default.

For me it worked like this: sudo ln /usr/bin/python3.8 /usr/local/bin/python.

Youtube-dl is a Python program, not a Python2 or Python3 program. When Python2 was more of a thing, and when yt-dl was created, Python2 was Python. My personal memory of Pythons doesn’t go back to Python 1.x, but I gather that regular small changes in language behaviour were typical between 1.x and early 2.x versions, without a big fork as happened with 2->3.

As Python3 became more widespread, compatibility shims were added to yt-dl so that the code now uses a subset of Python3, avoiding incompatible syntax (eg f'{expression}') and with certain incompatible library calls hidden under aliases that invoke a shim suitable for the actual Python version.

Without speaking for Debian, I believe that this was their plan:

  • remove the python executable (alias) to flush out programs that don’t mention 2 or 3
  • switch all packages that use Python to say one or the other explicitly
  • allow users to provide a default for other Python programs by installing one of the mutually incompatible python-is-python3 or python-is-python2 (while it lasts).

In this framework, if you as a user or system admin have Python programs that care about the Python version but just ask for python, you should decide where the majority lies, install the appropriate python-is-… package for those programs, and fix the others. yt-dl won’t care whether you give it 2.7 or 3.9 (eg, but especially as I run those): it’s just caught in the cross-fire.

This is just papering over the underlying problem that the Python language was forked incompatibly, like a toy language, but at least GvR did it more or less himself: JavaScript needs an entire standards committee.

Ubuntu 22.04

sudo ln /usr/bin/python3 /usr/local/bin/python sudo apt install python-is-python3

@pablodz, It Works for me!

So either of the proposed solutions should work, assuming that Kubuntu 20.04 still has python-is-python3.

The proposal with the ln command is making a link in the /usr/local/bin/ directory, which is normally ahead of the main system directories in the PATH, so that typing python causes python3, which is actually python3.8, to run.

Don’t the original suggestions here help?