tombulled / python-youtube-music

Python 3 YouTube Music Web API Client
GNU General Public License v3.0
64 stars 13 forks source link

Python doesn't find the package #9

Closed nicolapreda closed 3 years ago

nicolapreda commented 3 years ago

I tryed to insert this code and run it, but, after the installation of the package, python doesn't find it. image How can I resolve this error? image

tombulled commented 3 years ago

Your file is named ytm.py which Python will recognise as a module named ytm, which is also the name of the module you're trying to import. To resolve this issue, rename your ytm.py file to something else (e.g. app.py)

nicolapreda commented 3 years ago

Your file is named ytm.py which Python will recognise as a module named ytm, which is also the name of the module you're trying to import. To resolve this issue, rename your ytm.py file to something else (e.g. app.py)

If I rename the file, it gives me this error:

image

tombulled commented 3 years ago

In app.py you use the line:

ytm = ytm.YouTubeMusic()

This will overwrite the reference to the ytm module, which is then used again in the line:

return song_url(ytm.YouTubeMusic().search_songs(query)['items'][0]['id'])

To fix this, your code should look something like this:

import ytm

youtubemusic = ytm.YouTubeMusic()

def song_url(song_id: str) -> str:
    return ytm.utils.url_ytm('watch', params = {'v': song_id})

def search(query: str) -> str:
    return song_url(youtubemusic.search_songs(query)['items'][0]['id'])

print(search('liztomania'))

Hope this helps!

nicolapreda commented 3 years ago

image

Thank you very much!! I didn't think the name of the variable would give problems ... XD