Problem installing the python-kasa package for use with TP-Link HS110

Reference Python code to read TP-Link HS110 - #7 by sxw thread - Mod

When I try, following the instructions at https://pypi.org/project/python-kasa/ I see:

$ pip install "python-kasa" --pre
Defaulting to user installation because normal site-packages is not writeable
ERROR: Could not find a version that satisfies the requirement python-kasa
ERROR: No matching distribution found for python-kasa

I’m not familiar enough with python to understand what’s wrong.

If you are trying this on the emonpi, then “pip” is the python2.7 version. All of this stuff is python3, so you need to use “pip3” in order to install libraries.

One, slightly separate, word of warning. TP-Link recently pushed out new firmware to all of the UK HS110 plugs. If your plugs have been connected to the internet, then it is likely that they will have received this new firmware and python-kasa, and the script above, will not work. TP-Link have made radical changes to the communication protocol.

I’m working on changes to python-kasa to support the new protocol - they’re in this GitHub PR - Add support for the new encryption protocol by SimonWilkinson · Pull Request #117 · python-kasa/python-kasa · GitHub - but they aren’t done yet.

Thanks. No I’m on an openSUSE box at the moment and the output is identical if I use pip3 anyway. So I’m still looking to understand what it means.

Ah, I seem to remember something about that. Fortunately I’m a Luddite dinosaur and although my HS-110 is on my guest network since it’s an IOT device, the guest network is NAT-isolated from the Internet. Anyway my existing scripts are stll working :grinning:

Good to hear.

To me that is suggesting the current user doesn’t have relevent permission to install the package to the main system wide package location. Have you tried using sudo? I generally use sudo with pip to install system wide as often scripts are run as other users eg as root via cron or services etc.

Does go against official advice though and can have unexpected consequences (so I read).

Yes, that is correct. But as the message also says, that is not a problem. It installs into the current user’s location and since that user is pi and that is the user that needs to run the script, there’s no problem.

1 Like

Indeed it does, but it’s a less than ideal “fix” for what can be several less than ideal issues.

If you follow official recommendations you shouldn’t use pip to install packages when you have a distro package manager in use, if at all avoidable. Begs the question why is PIP in the distro repositories? (rhetorical question, I know it’s to install and manage packages that are not available in the distro repo, so it is recognised there is a real need to use both).

You should never update PIP via PIP if it was installed via a distro package manager, so why is the function not disabled or something when installed via such a route?

Regular PIP installs on a per user basis so until we crack using other users rather than running everything as pi, using any python package installed via PIP could be problematic, on that note putting “sudo” at the beginning of pretty much every line in the OEM scripts sort of undermines any intention of using users and sudo (and therefore PIP) correctly.

It is recommended that everything python is installed and run in virtualenvs (venv in Py3) but I do not see that in widespread practice anywhere, not just OEM.

I read somewhere in one of the many PIP(3) guides “you should never use sudo when installing from trusted sources” which make little sense if a source is trusted of course you can use sudo if that works for you, the source is “trusted”!!! Maybe a typo but I would agree you should be very wary of using sudo when installing from any untrusted sources such as going direct to Mosquitto repos for example, but you won’t get far trying to install the mosquitto package without sudo regardless of where you are sourcing it. So you should always be cautious of arbitrary code being run as root when installing anything from anywhere, but there are genuine reasons for using sudo, eg when installing a python package vis pip globally for all users.

I’m not saying it’s right! I’m saying it works when all else is less than ideal.

Can we keep any other replies about pip and python in the other thread Brian has created and keep this thread for discussion of HS110 related issues, please

I wasn’t sure if maybe the 2nd and 3rd lines were a result of line one in that yes it was installed where pi can find it but can the system find it, does the user pi’s path need adding to path (for example)? since the python and pip were (presumably) installed via a distro package manager.

Also when you come to run this will you create a service or use a cron, either will require running as user pi to find the package in pi’s path.

However I also wonder if it’s simply saying there is no openSUSE package available? I always use very mainstream distro’s. Scrub that! It would have just said as much I guess.

I think I found the error eventually.

The version of python is too old. python-kasa needs 3.7 and I have 3.6. I believe it uses asyncio changes that are new to 3.7. So I’ll postpone my experiments until I do an upgrade.

It seems it’s listed for python 3, 3.7 and 3.8 (python-kasa · PyPI) unless this is a recent development.

Good luck with the experiments, I’m just editing my scripts now for the later protocols, they don’t use the kasa package.