Hey,
I’m having some issues getting the google-api-python-client to work on Anki.
I installed the necessary packages with pip to a target folder inside the Anki Add-Ons Folder and added the dist Folder to the sys path like I do with any other third party package.
In the following example:
pip install -t . functional google-auth google-auth-httplib2 google-api-python-client --upgrade
It works fine for other packages I tested, but appears to break on googles even though it gets properly installed.
A minimal example would be this:
AddOnFolder/
AddOnFolder/dist/
AddOnFolder/main.py
AddOnFolder/init.py
main.py looks like this:
import os
import sys
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "dist"))
import functional
import google.oauth2
I only added the functional to show that other packages work fine from the same folder.
Now what puzzles me is that when I run the same main.py as a standalone and not via anki, it works fine so I don’t believe it’s a missing dependency or path issue. Only when I let Anki run the main it fails with the error:
(Note that it accepts the functional import in the line above just fine).
main.py", line 7, in <module>
import google.oauth2
ModuleNotFoundError: No module named 'google.oauth2'
<U+2069>
I believe it is caused by the fact that the Anki Directory Anki/lib/ contains a folder called google and thus interferes with the import of the google package in dist/google/ since it’s used as a search path.
I thought adding the dist/ path at the front of the sys.path would solve it (since python checks in the directories in sequential order), but it doesn’t.
Renaming the dist/google/ to something else and changing the import google.oauth2
to the new name works, but causes more issues down the line since the google api itself uses imports from google.x , too.
I’m honestly not sure how to approach this issue or fix it and would greatly appreciate any help or guidance.