heggink / domoticz-icloud

iCloud device location python plugin for Domoticz
MIT License
1 stars 1 forks source link

pyicloud Import failure #1

Open jannnfe opened 6 years ago

jannnfe commented 6 years ago

Hello, i installed pyicloud and geopy with pip. I get this error in Domoticz log after activate the plugin:

2018-10-28 22:18:47.808 Error: (AppleDevices) failed to load 'plugin.py', Python Path used was '/root/domoticz/plugins/domoticz-icloud/:/usr/lib/python35.zip:/usr/lib/python3.5/:/usr/lib/python3.5/plat-x86_64-linux-gnu:/usr/lib/python3.5/lib-dynload'. 2018-10-28 22:18:47.808 Error: (Apple iCloud) Module Import failed, exception: 'ImportError' 2018-10-28 22:18:47.808 Error: (Apple iCloud) Module Import failed: ' Name: pyicloud' 2018-10-28 22:18:47.808 Error: (Apple iCloud) Error Line details not available.

How to solve this issue?

heggink commented 6 years ago

Hi Jannnfe, How did you install pyicloud and geopy? I have had quite some issues myself with multiple versions of python where some of the python libraries installed were not in domoticz' python path (as per your first line of your log). Did you pip3 install of pip install? The last installs using python2.7 rather than python3. I am not a python expert by any means but I believe that, if this is the issue, you should be able to use sudo pip3 install pyicloud and geopy. H

jannnfe commented 6 years ago

Hey, It really has to be something with my Python. I do not know my way either, but I think I found the problem, but I can not solve it.

On startup Domoticz logs its use Python 3.5.2:

2018-10-29 11:51:08.317 Status: PluginSystem: Started, Python version '3.5.2'.

I have installed:

python -V Python 2.7.12

python3.5 -V Python 3.5.2

python3 -V Python 3.6.7

pip is using for Python:

pip -V pip 18.1 from /usr/local/lib/python2.7/dist-packages/pip (python 2.7)

pip3 is using for Python3.6:

pip3 -V pip 18.1 from /usr/local/lib/python3.6/dist-packages/pip (python 3.6)

So the /usr/local/lib/python3.5/dist-packages directory is empty using pip3 because its using Python 3.6. I don't know how to point pip3 to Python 3.5. I searched hours in google but nothing worked for me. Maybe do you have an idea? Thanks :)

heggink commented 6 years ago

Sounds very similar to the issues I had. Have you tried installing with: sudo pip3 install pyicloud and sudo pip3 install geopy ? If it installs in python2.7 then domoticz will ignore it. If you find that it installs in a path which is not part of the domotivz python path then you have 2 options: 1) add PYTHONPATH to domoticz.sh startup or 2) edit plugin.py to add sys.path.append('/usr/local/lib/python3.5/dist-packages') just after import sys (this is what I did) I kow it's a shitty solution but python got very messy on my system due to a bunch of python3.6 ssl issues with domoticz a while back and I am not looking to reinstall from scratch so no option for me.

jannnfe commented 6 years ago

Yes with sudo pip3 install pyicloud and sudo pip3 install geopy it installs in Python3.6, so Domoticz will ignore it because it uses 3.5. Option 1): I will add PYTHONPATH=path/to/python3.6 ? Option 2): I will edit the plugin.py of domoticz-icloud or other?

Sorry for my stupidity but the whole Python stuff is new to me and I do not know it at all. Thanks :)

heggink commented 6 years ago

Simplest to do option 2: go to domoticz/plugins/iCloud (or whatever your plugin folder is called). edit plugin.py and add the 2 lines as below (you need import sys in order to do sys.path.append):

import Domoticz import sys sys.path.append('/usr/local/lib/python3.6/dist-packages')

from pyicloud import PyiCloudService from geopy.distance import vincenty import time

Before you make the change, ensure that geopy and pyicloud are indeed in /usr/local/lib/python3.6/dist-packages. If not then make sure you append with the correct path. There's probably much more elegant ways to fix this (like reinstalling the python libraries in a folder of choice and getting domoticz to locate them there but I have spent hours and not managed it myself). btw, I would call it ignorance, not stupidity ;-) Ignorance is curable but stupitidy is ...

jannnfe commented 6 years ago

Thanks for your help. I think something is also missing after adding the sys to plugin.py. I have to look into that again later this day.

2018-10-29 13:43:35.901 Error: (AppleDevices) failed to load 'plugin.py', Python Path used was '/root/domoticz/plugins/domoticz-icloud/:/usr/lib/python35.zip:/usr/lib/python3.5/:/usr/lib/python3.5/plat-x86_64-linux-gnu:/usr/lib/python3.5/lib-dynload'. 2018-10-29 13:43:35.901 Error: (Apple iCloud) Module Import failed, exception: 'ImportError' 2018-10-29 13:43:35.901 Error: (Apple iCloud) Module Import failed: ' Name: six' 2018-10-29 13:43:35.901 Error: (Apple iCloud) Error Line details not available.

jannnfe commented 5 years ago

I found the motivation to look for it again, unfortunately without success. I'll have to give up the nice plugin now. Here someone had a similar problem with another plugin but that did not help me either

heggink commented 5 years ago

Hi jannnfe, It's a known issue on raspbian which is why Tsjippy suggests installing specifically in the plugin folder. Effectively, that's a shitty solution as it means that you need to install these in every plugin folder you need just because the python path does not find all previously installed versions. so rather that just pip3 installing these, install them with -t i.e. sudo pip3 install xxxxx -t path_to_where_you_installed_the_plugin if you do this for every plugin it can't find (pyicloud, geopy, six, ..) then it should work.

jannnfe commented 5 years ago

Great, now it works! :) The plugin but makes problems in connection with the two-factor authentication or?

heggink commented 5 years ago

Brilliant! I have not implemented 2FA myseelf but I know pyicloud supports it. I won't have time to make any changes due to extensive travel over the next couple of weeks. If you want to dig into this, be my guest!

FearNaBoinne commented 5 years ago

2FA is a big stinker, and even the official pyicloud is not supporting it right now (there's an alternative version, but that has other issues, primarily with a missing attribute (which seems to be defined, but just not recognized) called api.requires_2sa... So there's no way to make that work reliably. I somehow got it to authenticate manually with the keychain and an extra script, but there are definitely a few things that could be added... First off, an interactive 2SA setup would be nice Second, an interactive device selection would be nice, so I do not have to copy the device name manually Third, the ability to track multiple devices... Fourth, the ability to set the range of what is considered 'present'

I have tried to look at the code, but it is too much to quickly hack in, and I have tons of other things to resolve, both around Domoticz and elsewhere to bother too much with an iCloud presence plugin, no matter how nice it'd be.

Love the concept, cannot use it right now... :(