You are not logged in.

#1 2025-03-14 11:31:22

InFerYes
Member
Registered: 2012-11-13
Posts: 38

home-assistant No module named 'pymysql' or No module named 'MySQLdb'

I have installed home-assistant on my server via pacman (pacman -Syu home-assistant). Recently home-assistant has been unable to use it's recorder function because it can't connect to the database.

The database is a MariaDB instance on a remote server. I have verified that the connection string works and that it is correct.

Home-assistant gives me the error "No module named 'pymysql'"

I have installed pymysql via pacman (pacman -Syu python-pymysql) and verified that python picks it up by using python -c "import pymysql" and checking the exit code (0).

The wiki has an entry that says to remove the /var/lib/hass/deps/lib folder if there are any problems with ModuleNotFoundErrors in logs, but when I run the command from the wiki I get

rm: cannot remove '/var/lib/hass/deps/lib': No such file or directory

and indeed, there is no lib folder in /var/lib/hass/deps (where /var/lib/hass is actually a symlink: /var/lib/hass -> private/hass).


I have the same issue when I change the connection string from mysql+pymysql:// to simply mysql://, but then I get "No module named 'MySQLdb'". I have also installed the package python-mysqlclient because of this but to no avail.

Where is the lib folder located lately?
Does anyone else have a remote database server that they connect to and how is it set up in the home-assistant configuration?

I hope someone can shed some light on this.



Thank you!

Offline

#2 2025-05-02 21:56:45

Redraikiri
Member
Registered: 2025-05-02
Posts: 1

Re: home-assistant No module named 'pymysql' or No module named 'MySQLdb'

Also had problems with this and found your post.
I tried a few things out, and I think I found a solution.

You could execute something like:

 /var/lib/hass/.venv/bin/python -m pip install mysqlclient 

(MySQL db is included in mysqlclient).
Executing Python from the venv directory itself seems to include it properly.

To be sure it is installed in future startups, I included the line in /usr/lib/systemd/system/home-assistant.service. And triggered a daemon-reload before restarting the home-assistant service .



Hope this helps smile

Offline

Board footer

Powered by FluxBB