pwittchen/spotify-cli-linux

No Module Named Dbus after Installing Dbus

ShiromMakkad opened this issue · 22 comments

I can't seem to get rid of the "No module named dbus" error. I've install dbus with no erros, and dbus-send is recognized as a command. I've installed spotify-cli-linux both manually and from pip and neither one has solved the problem. Is spotify-cli-linux compatible with the current version of dbus?

My full error
Traceback (most recent call last): File "/home/shirom/miniconda3/bin/spotifycli", line 5, in <module> from spotifycli.spotifycli import main File "/home/shirom/miniconda3/lib/python3.7/site-packages/spotifycli/spotifycli.py", line 8, in <module> import dbus ModuleNotFoundError: No module named 'dbus'

I don't know which distro are you using. Have you tried to install python-dbus package with your package manager? This issue is described here: https://github.com/pwittchen/spotify-cli-linux#dbus and usually it should fix the problem.

Yes, I used sudo apt-get install python-dbus. One thing to note is that I'm using Windows Subsystem for Linux with Ubuntu 18.04, but that shouldn't matter at all. Also, dbus seems to be installed correctly, so I don't think it's WSL.

I don't know if it's gonna work on Windows with Linux subsystem. This tool was made specifically for Linux and may not work on other systems.

Windows Subsystem for Linux was designed to emulate Ubuntu as closely as possible, and I have yet to find one command line tool that doesn't work outside of ones that do system monitoring or GUIs. That being said, WSL 2 is releasing in 2020, so that may improve compatibility.

In trying to install spotify-cli-linux on KDE Neon (which runs Ubuntu under the hood) I also ran into this issue even though I did install python-dbus which, as you can see below, was...already installed.

$ sudo apt-get install python-dbus
Reading package lists... Done
Building dependency tree       
Reading state information... Done
python-dbus is already the newest version (1.2.6-1).
python-dbus set to manually installed.
Starting pkgProblemResolver with broken count: 0
Starting 2 pkgProblemResolver with broken count: 0
Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

The stack trace is this:

$ spotifycli
Traceback (most recent call last):
File "/home/anavarre/.local/bin/spotifycli", line 11, in <module>
load_entry_point('spotify-cli-linux==1.6.0', 'console_scripts', 'spotifycli')()
File "/usr/local/lib/python3.7/site-packages/pkg_resources/__init__.py", line 489, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/usr/local/lib/python3.7/site-packages/pkg_resources/__init__.py", line 2793, in load_entry_point
return ep.load()
File "/usr/local/lib/python3.7/site-packages/pkg_resources/__init__.py", line 2411, in load
return self.resolve()
File "/usr/local/lib/python3.7/site-packages/pkg_resources/__init__.py", line 2417, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
File "/home/anavarre/.local/lib/python3.7/site-packages/spotifycli/spotifycli.py", line 8, in <module>
import dbus
ModuleNotFoundError: No module named 'dbus'

Python info

$ python -V
Python 3.7.3
$ pip --version
pip 20.0.2 from /home/anavarre/.local/lib/python3.7/site-packages/pip (python 3.7)

@anavarre same issue with me

It happens to some users (usually on Ubuntu). I provided one solution here: https://github.com/pwittchen/spotify-cli-linux#dbus. I don't know what else can be done to solve this.

@pwittchen yeah I tried everything. It works for python2 but not python3

I think they messed something up in the recent spotify or dbus release.

When I type:

dbus-send --session --dest=org.freedesktop.DBus --type=method_call --print-reply /org/freedesktop/DBus org.freedesktop.DBus.ListNames

I cannot see spotify on my computer and now I cannot use spotify both with spotify-cli-linux and playerctl. Spotify app and dbus seem to be very unstable.

It'w weird. It started working on my desktop back again, but I don't know the reason. Maybe it's related to updates of some dependencies or system packages. I'm sure it's an issue with system dbus or connecting to dbus by the spotify app - not the script itself.

It happens if anaconda is installed and by default activated. I tried deactivating anaconda and everything just works fine. My impression is issue of Anaconda with dbus.

FYI I had this exact problem but solved it. I looked around and found this post on stackoverflow which instructed me to install a bunch of dependencies

Ubuntu 20.10 Groovy doesn't seem to have the python-dbus package and apparently the package python3-dbus doesn't help, so I'm kinda stuck here.

@agucova there must be something wrong with dbus on this Ubuntu version. Unfortunately, I cannot check it at this moment, because I'm using a different distro.

@pwittchen I was able to trace the error to conflicting python installs. I was using Linuxbrew, so using brew install dbus glib and pip install dbus-python worked fine.

a-t-0 commented

On command:

sudo apt install python-dbus

I also received error:

E: Package 'python-dbus' has no installation candidate

And as @ssboisen indicated, the commands from this stack post, resolved the issue for me:

sudo apt install build-essential libdbus-glib-1-dev libgirepository1.0-dev
pip install dbus-python

After that, the:

no module named dbus
was resolved and I was able to directly run:

spotifycli

without having to install python-dbus

Ubuntu version:

lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 21.10
Release:	21.10
Codename:	impish
a0x14D commented

try : pip install dbus-python

@maybe it works

Guys, same issue here but I'm using Arch...

ModuleNotFoundError: No module named 'dbus'

Does anyone have the solution?

python-dbus (installed)

@FelypeInvictus It's working on Arch. This issue is usually related to lack of dbus/python-dbus, outdated dbus packages in the system or old/wrong python version.

@pwittchen Problem solved. I was installing the dependencies and the program using pipx (I can't use pip).
I tried installing like this (as is recommended) but was forced to use pipx.

Example:

pip install lyricwikia
error: externally-managed-environment

× This environment is externally managed
╰─> To install Python packages system-wide, try 'pacman -S
    python-xyz', where xyz is the package you are trying to
    install.
    
If you wish to install a non-Arch-packaged Python package,
create a virtual environment using 'python -m venv path/to/venv'.
Then use path/to/venv/bin/python and path/to/venv/bin/pip.
    
If you wish to install a non-Arch packaged Python application,
it may be easiest to use 'pipx install xyz', which will manage a virtual environment 
for you. 
Make sure you have python-pipx
installed via pacman.

note: If you believe this is a mistake, 
please contact your Python installation or OS distribution provider. 
You can override this, at the risk of breaking 
your Python installation or OS, 
by passing --break-system-packages.
hint: See PEP 668 for the detailed specification.

I uninstalled everything and installed the dependencies and spotifycli manually (via git clone). Now it works...
I can't say precisely what caused this problem, but it appears to be the package manager (pipx).