ytdl-org / youtube-dl

Command-line program to download videos from YouTube.com and other video sites
http://ytdl-org.github.io/youtube-dl/
The Unlicense
131.68k stars 9.97k forks source link

/usr/bin/env: ‘python’: No such file or directory #30129

Open yoones opened 2 years ago

yoones commented 2 years ago

Checklist

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:

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.

dirkf commented 2 years ago

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.

Almaz commented 2 years ago

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

nudgegoonies commented 2 years ago

Adjusting the shebang of youtube-dl to #!/usr/bin/env python3 works too.

yoones commented 2 years ago

Adjusting the shebang of youtube-dl to #!/usr/bin/env python3 works too.

Yes but changing the shebang manually only lasts until the next update of youtube-dl.

nudgegoonies commented 2 years ago

Yes, but everything else is a workaround and not a fix. I have explicit not installed the python-is-python3 debian package to be able to find every shebang that ist wrong.

dirkf commented 2 years ago

If you installed the python-is-python3 package they wouldn't be wrong, would they? And you can always uninstall it if you want none of your Python scripts to run, which is much more straightforward than managing a whole lot of manually patched scripts.

I take the position implied by the name of the package. If your script needs Python 2 put that in the shebang; otherwise just ask for Python. Let's hope that we don't have to go through all this again with some future Python 4.

nudgegoonies commented 2 years ago

Every new major Python X version should be no trouble as long all scripts use pythonX in the shebang and as long no one depends on a default python executable to be a specific major version which will definitely increase in the future ;-)

jehoshua7 commented 2 years ago

Have just installed youtube-dl as per the instruction on Kubuntu 20.04.3 , and got the error message. If I do a locate -i python , there are many pages. Does anyone know where the python executable is on Kubuntu please ? I can see /etc/python2.7/ , /etc/python3/ , and /etc/python3.8/ paths but they do not have the library,etc

dirkf commented 2 years ago

Don't the original suggestions here help?

jehoshua7 commented 2 years ago

It seems the Kubuntu configuration setup has nothing in /usr/local/bin though.

ls -al /usr/bin/pyth*

lrwxrwxrwx 1 root root 9 Dec 28 2020 /usr/bin/python3 -> python3.8 -rwxr-xr-x 1 root root 5490488 Nov 27 07:14 /usr/bin/python3.8 lrwxrwxrwx 1 root root 33 Nov 27 07:14 /usr/bin/python3.8-config -> x86_64-linux-gnu-python3.8-config lrwxrwxrwx 1 root root 16 Mar 13 2020 /usr/bin/python3-config -> python3.8-config

ls -al /usr/local/bin/

total 51172 drwxr-xr-x 2 root root 4096 Jan 15 18:17 . drwxr-xr-x 10 root root 4096 Aug 1 2020 .. -rwxr-xr-x 1 root root 529 Jun 5 2021 bundle -rwxr-xr-x 1 root root 531 Jun 5 2021 bundler -rwxr-xr-x 1 root root 50540544 Sep 4 20:16 hugo -rwxr-xr-x 1 root root 1837828 Jan 15 18:17 youtube-dl

whereis python

python: /usr/bin/python3.8-config /usr/bin/python3.8 /usr/lib/python2.7 /usr/lib/python3.8 /usr/lib/python3.9 /etc/python2.7 /etc/python3.8 /usr/local/lib/python3.8 /usr/include/python3.8

dirkf commented 2 years ago

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.

jehoshua7 commented 2 years ago

Thanks for your help @dirkf . The ln did nothing ,but the package `python-is-python3' did the trick.

pablodz commented 2 years ago

3.10 python3 uprgade on ubuntu 22 was the error

unit-cesar commented 2 years ago

Ubuntu 22.04

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

@pablodz, It Works for me!

dirkf commented 1 year ago

Here is a script that can be used in POSIX shell, adapting as necessary, to modify the shebang of single file self-extracting yt-dl program, and possibly any other script.

byoso commented 1 year ago

Linux solution So the dev team for some reason doesn't want to use #! /usr/bin/env python3 and prefers to ask the users to modify their system with python-is-python3. I wont argue with that, but as I don't want to do this, I show you a simple alternative solution on linux. Just add this script in your ~/bin directory (because it is in the PATH and without sudo, if you don't run an ubuntu fork os, add this directory to the PATH within the .bashrc) and use it to launch the app instead of using directly youtube-dl:

myyoutube-dl (make it executable)

#! /usr/bin/env python3

import sys
import os

args = sys.argv[1:]

params = ""
for arg in args:
    params += f" {arg}"

os.system(f"python3 /usr/local/bin/youtube-dl{params}")

Note: If you are running an ubuntu flavor OS and you haven't created the bin folder before, you must first create this folder and then reboot, the ubuntu's .bashrc is already configured to recognize this bin folder on boot and then add it to the PATH.

dirkf commented 1 year ago

Why on earth would you do that rather than just making a python link on your PATH that points to your preferred Python?

~/bin may be in your PATH but that isn't necessarily or widely so.

some reason.

byoso commented 1 year ago

Well, first linux did it wrong, and should have do the same as MacOs, but they didn't. Here you have the choice between:

Both are bad choices, but your solution is to ask your linux users to make their system incompatible with python2. If totally burning the bridges with python2 wasn't an issue, you'd use #! /usr/bin/env python3, and for some reasons you are not, for the same reasons, maybe to be able to run old python2 scripts, some linux users may not want to 'break' this ability of their system to potentially install and run python2. So this is where my little script above can solve this problem without changing the app nor the users systems.

nudgegoonies commented 1 year ago

Python 2 and 3 are incompatible major versions. With the introduction of Python 4 we will have the situation again that we need two different Python versions installed at the same time. A Python 3 program will not run on Python 2 and Python 4. So why rely on a default python that could be any major version rather than setting the required major version in the shebang which automatically selects the correct version?

byoso commented 1 year ago

@nudgegoonies I totally agree I agree with you, this is a linux issue, they had the silly idea to call python2 just python.

And if I understood correctly, what python-is-python3 is just mapping 'python' to python3, it wont analyze the code to know if it is python3 or 2. As there are still some python2 apps that could be usefull (I can't tell any to be honest...), I prefer not to change my system that way unless some official distros are doing this themself, in my opinion it is to soon to do that.

And using this script is not more complex then installing python-is-python3, so, I just share an alternative to python-is-python3 which is not bad, but not to my taste.

For now, solving this on the dev side is just adding one character "3" in the __main__.py file only, when you will switch to python4, in a few years, you'll have to change it for a "4", it is less work than having this discussions :). Not to mention that when python will come in version 4, it will mean that running python3 code with python4 will break, so you'll have to specify "4" anyway, or ask people to destroy their ability to run python3 and 2...

But I argued too much with this.

dirkf commented 1 year ago

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:

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.

byoso commented 1 year ago

Ok, thank you for making this point more clear. If I understand, the team wants to keep the app compatible with both 2 and 3. I will try to think about that, maybe it is possible to keep compatibility with both 2 and 3 another way.

superbonaci commented 3 months ago

macOS 14.5 does not have any python*, only python3.

dirkf commented 3 months ago

With such macOS, or if Debian abandons the package mentioned, either

superbonaci commented 3 months ago

Does the -m pip install the latest nightly and keeps it updated? Because the stable version 2021.12.17 is broken for certain videos.

dirkf commented 3 months ago

In fact, the stable version is almost completely useless for YouTube and probably many other sites that it originally supported.

With the pip solution, you need to specify the .tar.gz archive from the appropriate release page to prevent pip from looking in pypi.org. The second solution with the bundled executable will support -U to update to the latest nightly release.

superbonaci commented 3 months ago

Why do you have to call directly python? They already made a mess renaming all python2 links to python for compatibility, then python3 to python2 or python, and now they want to revert the changes.

I can't make a python symlink to python3 system wide because can break something. python 1 and 2 are end of life this is why macOS does not include them anymore.

Could you offer 3 different nightlies where each one calls a different python? So brew.sh can download the best one for each system and not just call "python" for everybody. For example:

https://github.com/ytdl-org/ytdl-nightly/releases/tag/2024.06.21_python1 https://github.com/ytdl-org/ytdl-nightly/releases/tag/2024.06.21_python2 https://github.com/ytdl-org/ytdl-nightly/releases/tag/2024.06.21_python3

All files inside: https://github.com/ytdl-org/ytdl-nightly/releases/download/2024.06.21_python3/youtube-dl https://github.com/ytdl-org/ytdl-nightly/releases/download/2024.06.21_python3/youtube-dl.exe

dirkf commented 3 months ago

If you don't have a python executable now, symlinking your Python3 as python shouldn't affect anything (though there are weird code tricks that could be affected). A paranoid user could put the python link in a directory that's only added to PATH in the user's shell session, or only when needed, etc.

Other than the offered solutions, do the equivalent of alias youtube-dl="python3 wherever/youtube-dl" in your shell. You can also install the latest master using Homebrew (read their docs for the details that I have now forgotten). Or build the program yourself, or ask Homebrew (or similar) to package the release.