Youtube-dl (update/Uninstall/Install/Python3/Pip3) nightmare!

Hello,

I’m a longtime user of various Linux distributions (mostly Ubuntu) but not until I got a Pi, did I really start getting familiar with the command line.
I am currently using UbuntuStudio- VERSION=“20.04.1 LTS (Focal Fossa)” and am having trouble with youtube-dl.
Basically, I’ve updated,installed & uninstalled youtube-dl through so many methods that I’m lost and don’t have a working youtube-dl.

(Note-there’s a restriuction on links for new users. My curl and wget commands have url links to the youtube-dl site.
Wherever there is supposed to be a url, I’ve replaced with “(url goes here)”
i hope this is ok.)

But here’s how it happened:
I succesfully used youtube-dl with a youtube video but minutes later, was unable to download a different video:

So i checked the version of youtube-dl that I was using and found that it was not the latest version “youtube-dl 2020.07.28.”

I then tried to update the version. This is where I messed everything up. I tried without luck:
sudo apt-get update
sudo-apt-get update youtube-dl

And then after various webpages…
37 sudo apt-get install youtube-dl
263 youtube-dl -U
264 sudo apt-get update youtube-dl
265 sudo apt-get update youtube-dl -U
267 youtube-dl -u
268 $ sudo pip install -U youtube-dl
269 $ sudo pip3 install -U youtube-dl
274 sudo pip install -U youtube-dl
275 sudo pip3 install -U youtube-dl
276 sudo apt-get upgrade youtube-dl
277 sudo pip3 install -U youtube-dl
278 sudo apt-get install -U youtube-dl
279 sudo apt-get youtube-dl
280 sudo apt-get install youtube-dl
283 sudo apt-get remove -y youtube-dl
289 sudo apt-get install youtube-dl
290 sudo apt-get remove youtube-dl
292 sudo curl (url goes here)
293 sudo chmod a+rx /usr/local/bin/youtube-dl
301 sudo pip install -U youtube-dl
302 sudo pip3 install -U youtube-dl
304 sudo chmod a+rx /usr/local/bin/youtube-dl
342 sudo wget (url goes here)
343 chmod -R 755 /usr/local/bin/youtube-dl
344 sudo chmod -R 755 /usr/local/bin/youtube-dl
348 pip3 youtube-dl -U
350 sudo snap install youtube-dl

I know, It’s a mess

Anyways, Here’s where i think I stand:
I have these pythons installed:

which python3
/usr/bin/python3

which python2
/usr/bin/python2

I have this youtube-dl folder here

which youtube-dl
/usr/local/bin/youtube-dl

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

Tried to run from: /usr/local/bin/youtube-dl
/usr/local/bin$ youtube-dl (url goes here)
/usr/bin/env: ‘python’: No such file or directory

So then, I remembered my very brief encounter with pip3 (had to use photorec_sort) and tried pip3 install:

sudo pip3 install youtube-dl
Requirement already satisfied: youtube-dl in /usr/local/lib/python3.8/dist-packages (2020.7.28)

Here is what I have in that directory:

/usr/local/lib/python3.8/dist-packages$ ls

youtube_dl  youtube_dl-2020.7.28.dist-info

The youtube_dl directory has the YoutubeDL.py program

So I tried this from that directory:

/usr/local/lib/python3.8/dist-packages/youtube_dl$ pwd
/usr/local/lib/python3.8/dist-packages/youtube_dl

/usr/local/lib/python3.8/dist-packages/youtube_dl$ python3 YoutubeDL.py (youtube url goes here)

and this is what I got:

/usr/local/lib/python3.8/dist-packages/youtube_dl$ python3 YoutubeDL.py (youtube url goes here)
Traceback (most recent call last):
File "YoutubeDL.py", line 31, in <module>
	from .compat import (
ImportError: attempted relative import with no known parent package

As you can tell, I know just enough linux to get myself in trouble. Can anyone please help me return to a working youtube-dl status?

Thank you in advance,
Zeke

Taking a guess but the key may be your error here:

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

It’s looking for the directory “python”, not the one you have: “python3”. You can softlink the directory as follows:

sudo ln -s /usr/bin/python3 /usr/bin/python

Then try youtube-dl again.

1 Like

This worked. It’s the exact same suggestion I received from someone on the Reddit “youtube-dl” board. That’s OK. I was very happy to receive the confirmation that this is the path I needed to take.

I have read about the link command but have never used it and I would have never thought of it as a solution because I didn’t know what was going on.

A quick man search revealed that we’ve established a “symbolic link.”

it was also suggested that I remove any instances of “youtube-dl” and start fresh with wget straight from the source.

It’s working now so I’m a scared to start that process right now. Know what I mean?

Thank you again!

Zeke

1 Like

I am a heavy youtube-dl user and in general I would always recommend the newest version, especially on Ubuntu and Debian, not the version from the repositories, so remove it:

sudo apt purge youtube-dl

You have to decide if curl or wget or whatever but I like pip and use it to install the most recent version. But here comes the thing, the pip command is for Python 2 and pip3 for Python 3. As Python 2 is or will be deprecated it is recommended to use pip3 that uses python-pip3 as its backend.

At least you resolved your problem but you can still remove the version of youtube-dl using Python 2:

pip uninstall youtube-dl

On a side note: For security reasons it is better to use pip as your user instead of root.

1 Like

I personally use the snap package (snap install youtube-dl).

That way it gets automatically updated and I don’t have to worry about managing python stuff just to download silly cat videos… :slight_smile:

1 Like

I didn’t get a pip user, short of creating one you could just install it to the user directory.

How’s this look to you from the ground up?

sudo apt purge youtube-dl
sudo apt install python3-pip
pip3 install youtube-dl --user # Output for me was installation to: ~/.local/bin/
# Append the following to your ~/.bashrc file:
export PATH=“${PATH}:~/.local/bin/”

Update package:

pip3 install youtube-dl -U

I applaud your honesty lol

1 Like

Absolute viable option though I do not use snap nor does my distribution. :wink:

That is exactly how it works and @WalJT is right to prefer the snap package in that case especially if you are on Ubuntu but I still use pip like I did years before and because I never reinstall I am still on that path. :slight_smile:

Edit: It is especially the way to do it on Ubuntu, somehow, because in Fedora or Mageia you actually do not have to mess with your PATH.

Non able youtube dl. Youtube channel url switch