youtube-dl: youtube-dl cant find python if only python3 on system

Checklist

  • I’m reporting a broken site support issue
  • I’ve verified that I’m running youtube-dl version 2021.12.17
  • 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

$ youtube-dl -v https://youtu.be/dAywaOWz8Tc
/usr/bin/env: ‘python’: No such file or directory
$ which python3
/usr/bin/python3
$ which python
$ # no output

Some other system info if relevant (since -v doesn’t work in this case):

  • OS: Kubuntu 22.04 LTS
  • Python version: Python 3.10.4 (default)

Description

youtube-dl can’t seem to find Python on systems that only have python3 by default, like Ubuntu 22.04 (i.e. only a defined ‘python3’, no ‘python’ alias). When you try to use it, it simply says /usr/bin/env: ‘python’: No such file or directory (details in verbose log output above).

I used the workaround of simply passing youtube-dl to python3 (python3 $(which youtube-dl) <URL>), and all youtube-dl functions work fine then. But this is an ugly workaround and I hope there’s a more elegant solution.

Idk what that solution is… I don’t want to alias python='python3' in case I need to install python2 in the future and the alias breaks stuff. But I also don’t want to install python2 just for youtube-dl since it works fine using python3; it just can’t find it by default (the readme says youtube-dl requires “Python interpreter, version 2.6, 2.7, or 3.2+”; so users shouldn’t have to install a Python2 if they already have a Python3.2+).

I imagine the best solution would be for youtube-dl to check if python3 exists if python can’t be found.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 20 (10 by maintainers)

Most upvoted comments

I decided to alias youtube-dl="python3 $(which youtube-dl) " in my .bash_aliases, which is an elegant-enough solution for me. (the youtube-dl I downloaded was via the manual curl-chmod method, not via apt or pip (I’d rather avoid snaps, and I’d rather not deal with pip)).

But anyways, I’m just glad to see from your linked issue that you’re at least aware of this bug. I’ll leave this issue open if anyone has anything to add, but my problem’s basically solved - you can close it if you like.

cd /usr/bin ln -s python3 python

i wonder why would anyone ever again need to use python2 except for some testing and development

I don’t see how bundling an universal Python (even if only considering x86) would be possible, much less without adding another 100% to the size for Py for every OS.

^ Hell, even converting Py from C to Rust wouldn’t be a good option. Maybe Jython, but ytdl would have more things to consider due to the diffs between CPython and Jython on the technical level.

The simplest I know would be to release separate ytdl binaries “targeting” Py 2 or 3 that only differ by the shebang, since ytdl will run on both no problem.

yt-dl is a program that can run on Python 2 or Python 3 interchangeably, without the use of dependencies like six or 2to3. The guidance in these links is not entirely helpful for yt-dl.

yt-dl in Unix-like environments relies on a #!/usr/bin/env python line, which finds the first python executable in the PATH. Since Python 3.5+ may work better, we want yt-dl to run under those if available, but whatever configuration is used should not cause other Python2-specific programs, which don’t dynamically adapt to the version in use, to do so.

One solution that works is bundling a Python version in the yt-dl download. This is the typical type of yt-dl installation for Windows. However this approach requires a Python version that runs on all OS versions that yt-dl users are running and the bundling package to be supported and able to target those versions: neither of these is straightforward.

Another is installing with -m pip using your preferred Python (that supports pip, problematic in some legacy versions whose SSL setup doesn’t match PyPi’s CD’s requirements). But then platforms with no Python installed by default pose a hurdle for less technical yt-dl users.

Greetings, if you’re unsure you might break something, you can use designed commands that do very much the same but in officially recommended manner but if something expects python2 it better be converted to python3 anytime soon

for Debian and clones: https://linuxconfig.org/how-to-change-from-default-to-alternative-python-version-on-debian-linux for RHEL and clones: https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/configuring_basic_system_settings/assembly_configuring-the-unversioned-python_configuring-basic-system-settings

@capeguy63

youtube-dl cannot find python in my system. It is looking for python3 instead of just python. Is there a way to fix this in Windows? Or is it a separate issue?

On Window$ it doesn’t work like that, so you need to show proof.

Rather, open a new bug report and complete the template.

As the problem exists it needs to be acknowledged in the documentation, but before committing the changes it would be good to know if, eg, installing with python3 -m pip solves the problem.

Also the distro packages should fix their packaging, if necessary, which I’ll raise when the next release is imminent.