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

Can't Import the module. #5

Open
sumagnadas opened this issue Sep 3, 2021 · 9 comments
Open

Can't Import the module. #5

sumagnadas opened this issue Sep 3, 2021 · 9 comments

Comments

@sumagnadas
Copy link

I am trying to make a GUI overlay application for my media player which pulls my YT Music playlist and plays songs from there. Now leaving the overlay part and the GUI part, everything was complete so i thought that i should make it work with my media keys and so I found this module and installed it but while trying to import it shows the following error :

Traceback (most recent call last):
  File "media_player.py", line 7, in <module>
    from mpris_server.adapters import MprisAdapter
  File "/mnt/sda2/python/virtualenvs/yt-music-mod/lib/python3.8/site-packages/shiboken2/files.dir/shibokensupport/__feature__.py", line 142, in _import
    return original_import(name, *args, **kwargs)
  File "/mnt/sda2/python/virtualenvs/yt-music-mod/lib/python3.8/site-packages/mpris_server/__init__.py", line 1, in <module>
    from . import adapters, base, types, server, mpris, interfaces
  File "/mnt/sda2/python/virtualenvs/yt-music-mod/lib/python3.8/site-packages/shiboken2/files.dir/shibokensupport/__feature__.py", line 142, in _import
    return original_import(name, *args, **kwargs)
  File "/mnt/sda2/python/virtualenvs/yt-music-mod/lib/python3.8/site-packages/mpris_server/adapters.py", line 5, in <module>
    from .base import URI, MIME_TYPES, PlayState, DEFAULT_RATE, Microseconds, \
  File "/mnt/sda2/python/virtualenvs/yt-music-mod/lib/python3.8/site-packages/shiboken2/files.dir/shibokensupport/__feature__.py", line 142, in _import
    return original_import(name, *args, **kwargs)
  File "/mnt/sda2/python/virtualenvs/yt-music-mod/lib/python3.8/site-packages/mpris_server/base.py", line 15, in <module>
    Props = list[Prop]
TypeError: 'type' object is not subscriptable

What should I do to fix this?

@alexdelorenzo
Copy link
Owner

alexdelorenzo commented Sep 3, 2021

Thanks for opening an issue @sumagnadas. I'm sorry to hear that you're having a problem with mpris_server.

This looks like there might be a missing from __future__ import annotations in the version of mpris_server you got from PyPI.

Can you provide the output of the following two commands?

python3 -m pip show mpris_server
python3 --version

A quick fix for this might be to add from __future__ import annotations at the top of your media_player.py, or use Python 3.9 or above.

I'll check if the issue lies with mpris_server's package distribution, though.

@sumagnadas
Copy link
Author

This is the output of the commands:

(yt-music-mod) sumagnadas@hp-laptop:/mnt/sda2/python/projects/yt-music-mod$ python --version
Python 3.8.10
(yt-music-mod) sumagnadas@hp-laptop:/mnt/sda2/python/projects/yt-music-mod$ python -m pip show mpris_server
Name: mpris-server
Version: 0.4.2
Summary: Publish a MediaPlayer2 MPRIS device to D-Bus.
Home-page: https://alexdelorenzo.dev
Author: Alex DeLorenzo
Author-email: None
License: AGPL-3.0
Location: /mnt/sda2/python/virtualenvs/yt-music-mod/lib/python3.8/site-packages
Requires: typing-extensions, PyGObject, pydbus, emoji, unidecode
Required-by: 

Also I tried to fix the problem and it seems like the lines which were causing the problems (list[str]) were supposed to be like this i think - List[str]
The type validations were going from the wrong type.

@sumagnadas
Copy link
Author

sumagnadas commented Sep 4, 2021

So I checked to see if from __future__ import annotations was present or not and it seems like the import was present in all of the files which caused the problem, yet the error occurred.
I had to change a few lines which fixed the problem for me and the lines were mostly i think either type aliases or type validations like list[str] (which i changed to List[str] from typing) and tuple[str, str, str] (which I changed to Tuple[str, str, str] from typing)

@alexdelorenzo
Copy link
Owner

alexdelorenzo commented Sep 4, 2021

Thanks for providing the output of those commands. There's mpris_server==0.4.3 on PyPI that you can install like so:

python3 -m pip install mpris_server==0.4.3

Check that out, as I'm able to run it on Python 3.7 without a problem, so it should work with Python 3.8.10.

Regarding the use of typing.List[str] versus the parameterized container list[str], as of Python 3.7, use of the annotations import from __future__ should enable parameterized containers on Python 3.7 and 3.8, and is the default in 3.9, as per PEP 585. Strange that there's this inconsistency, but try the latest version on PyPI and see if you're still running into this error.

@sumagnadas
Copy link
Author

So I tried to install the version you told me but it can't find it. I also checked the official PyPI website and it says that the latest version is 0.4.2.
Also while I make my application work with the workaround as my part of the code wouldn't change even if the error is fixed, can you tell me how to make my app register the event handler?
I cant seem to get it as I am pretty new to event handling and stuff.

alexdelorenzo added a commit that referenced this issue Sep 4, 2021
@alexdelorenzo
Copy link
Owner

So I misinterpreted PEP 585, parameterized containers on Python <3.9 can only be used as variable or function annotations. Using parameterized containers for type aliases isn't supported on versions <3.9.

I apologize for misstating, this issue is 100% because of that misinterpretation. I made some changes to mpris_server itself, and tested it on 3.7.10. I pushed mpris_server==0.5.1 to PyPI, which should fix this issue.

Thanks again for reporting this!

@sumagnadas
Copy link
Author

I will try the fix as soon as possible. Until then, can you direct me to how to make a function or something which will register the event handler from my app's side?

@sumagnadas
Copy link
Author

Also, I was seeing the examples like cast_control and the one stated in the issue. In the issue, can you tell how does on_app_event() works and what I have to do with it exactly?:sweat_smile:

@asattelmaier
Copy link

I had exactly the same issues, I use Python 3.8.10 after the update to version mpris_server==0.5.1 it works without problems. Thanks for the fix and for the library!

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

No branches or pull requests

3 participants