Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File "ytmusicapi\ytmusic.py", line 102, in __init__ not found #250

Closed
SpikyPhrog opened this issue Jan 3, 2022 · 5 comments
Closed

File "ytmusicapi\ytmusic.py", line 102, in __init__ not found #250

SpikyPhrog opened this issue Jan 3, 2022 · 5 comments
Labels
question Further information is requested

Comments

@SpikyPhrog
Copy link

SpikyPhrog commented Jan 3, 2022

HI, I've used your wonderful api to create a player. The api works absolutely flawlessly, however when I tried to create an executable using pyinstaller and upon completion of the pyinstaller, when I run the exe file I get the following message:

`
Failed to execute script 'main' due to unhandled exception: [WinError3] The system cannot find the path specified: 'C:\Users\User\AppData\Local\Temp\_MEI39042\ytmusicapi\locales'

Traceback (most recent call last):
File "main.py", line 10, in
File "ytmusicapi\ytmusic.py", line 102, in init
FileNotFoundError: [WinError 3] The system cannot find the path specified: 'C:\Users\User\AppData\Local\Temp\_MEI39042\ytmusicapi\locales'
`

Any ideas on why would that happen or where can I get the installed files? Thanks a lot in advance!

@sigma67
Copy link
Owner

sigma67 commented Jan 4, 2022

I've never used pyinstaller, but I think you need to tell it to also include the package data of the dependency. ytmusicapi can't find the locales directory needed for localization, which it expects to be in the path specified in your error.

Perhaps this is also related to #223, you may try using resource_listdir like here in your fork of ytmusicapi

@SpikyPhrog
Copy link
Author

Thank you for the swift reply pal! I am afraid that unfortunatelly it did not quite work as it raised another issue now, this time about the supported languages. What I did with the solution that you suggested was to swap the original code to this one

supported_languages = [f for f in pkg_resources.resource_listdir('ytmusicapi', 'locales')] #locale_dir = os.path.abspath(os.path.dirname(__file__)) + os.sep + 'locales' #supported_languages = [f for f in os.listdir(locale_dir)] if language not in supported_languages: raise Exception("Language not supported. Supported languages are " ', '.join(supported_languages)) self.language = language try: locale.setlocale(locale.LC_ALL, self.language) except locale.Error: with suppress(locale.Error): locale.setlocale(locale.LC_ALL, 'en_US.UTF-8') self.lang = gettext.translation('base', **localedir=pkg_resources.resource_filename( 'ytmusicapi', 'locales'),** languages=[language]) self.parser = browsing.Parser(self.lang)

and of course imported the pkg_resources.. Now when I run it through the pyinstaller, once its done it yells the following error:

Traceback (most recent call last): File "main.py", line 10, in <module> YTMusic = YTMusic() File "ytmusicapi\ytmusic.py", line 106, in __init__ Exception

which line 10 is from ytmusicapi.setup import setup
and 106 is

raise Exception("Language not supported. Supported languages are "

I thank you ever so much for taking the time and I appreciate the effort to help pal! If there is no solution to it I will try to find another way to make it run not from the editor. Again, many thanks!

Screenshot_0

I did the screenshot purely because the formating in the preview looked awful. The red underlining are the things I've changed.

@sigma67
Copy link
Owner

sigma67 commented Jan 5, 2022

@sigma67 sigma67 added the question Further information is requested label Jan 7, 2022
@sigma67 sigma67 closed this as completed Jan 18, 2022
@glomatico
Copy link

I'm having this same issue. Any fix?

@rickyrorton
Copy link

I use auto-py-to-exe (gui for pyinstaller) and adding ytmusicapi under collect-all option worked for
image
and if you use from command line i think you just have to mention the following in the arguments
--collect-all "ytmusicapi"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants