[GH-ISSUE #250] File "ytmusicapi\ytmusic.py", line 102, in __init__ not found #193

Closed
opened 2026-02-27 22:08:32 +03:00 by kerem · 5 comments
Owner

Originally created by @SpikyPhrog on GitHub (Jan 3, 2022).
Original GitHub issue: https://github.com/sigma67/ytmusicapi/issues/250

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!

Originally created by @SpikyPhrog on GitHub (Jan 3, 2022). Original GitHub issue: https://github.com/sigma67/ytmusicapi/issues/250 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 <module> 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!
kerem 2026-02-27 22:08:32 +03:00
  • closed this issue
  • added the
    question
    label
Author
Owner

@sigma67 commented on GitHub (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

<!-- gh-comment-id:1004802363 --> @sigma67 commented on GitHub (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](https://github.com/sigma67/ytmusicapi/commit/013a1bfa8ad11989d02b9c09fa4b4098bed07b89) in your fork of ytmusicapi
Author
Owner

@SpikyPhrog commented on GitHub (Jan 4, 2022):

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.

<!-- gh-comment-id:1005230673 --> @SpikyPhrog commented on GitHub (Jan 4, 2022): 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](https://user-images.githubusercontent.com/58394916/148134749-1939341a-6654-46e4-b80a-081a8656e91a.png) I did the screenshot purely because the formating in the preview looked awful. The red underlining are the things I've changed.
Author
Owner
<!-- gh-comment-id:1005571044 --> @sigma67 commented on GitHub (Jan 5, 2022): I believe this is related: https://stackoverflow.com/questions/46474588/pyinstaller-how-to-include-data-files-from-an-external-package-that-was-install
Author
Owner

@glomatico commented on GitHub (Feb 15, 2022):

I'm having this same issue. Any fix?

<!-- gh-comment-id:1040685666 --> @glomatico commented on GitHub (Feb 15, 2022): I'm having this same issue. Any fix?
Author
Owner

@rickyrorton commented on GitHub (Jun 11, 2022):

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"

<!-- gh-comment-id:1152984658 --> @rickyrorton commented on GitHub (Jun 11, 2022): I use auto-py-to-exe (gui for pyinstaller) and adding ytmusicapi under collect-all option worked for ![image](https://user-images.githubusercontent.com/74890659/173201882-86b717d8-e3f6-4c8a-bd36-d34ac96c0cf7.png) and if you use from command line i think you just have to mention the following in the arguments ```--collect-all "ytmusicapi"```
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/ytmusicapi#193
No description provided.