Google-api-python-client: Breaking change: 1.8.1 breaks PyInstaller apps and any scenario where library is not installed with pip

Created on 21 Apr 2020  Â·  19Comments  Â·  Source: googleapis/google-api-python-client

Environment details

  • OS type and version: ANY
  • Python version: ANY
  • pip version: ANY (or N/A)
  • google-api-python-client version: 1.8.1

Steps to reproduce

  1. Install 1.8.1
  2. Attempt to compile Python app that uses googleapiclient to an executable

Expected results

executable compiles and runs as it did with 1.8.0 library

Actual results

executable compiles but fails at runtime with:

pkg_resources.DistributionNotFound: The 'google-api-python-client' distribution was not found and is required by the application

this is due to removing googleapiclient.__version__ and replacing with:

https://github.com/googleapis/google-api-python-client/blob/master/googleapiclient/model.py#L36

these issues will also occur if the library was not installed via pip (e.g. just cloned into a sub directory of the script).

process

Most helpful comment

Hey guys, I had the same issue with pyinstaller what did the trick for me was to roll back from
google-api-python-client from version 1.8.2 to 1.8.0. I hope this issue gets fixed soon. It wasn't fixed in 1.8.2 as commented due to the fact I was facing the same issue on 1.8.2

python -m pip install google-api-python-client==1.8.0

Thanks

All 19 comments

I get this error also when installing in pip3
module 'googleapiclient' has no attribute '__version__'

I was able to work around this with following changes to my PyInstaller .spec file:

extra_files = [copy_metadata('google-api-python-client')]

a = Analysis(['gyb.py'],
             excludes=['FixTk', 'tcl', 'tk', '_tkinter', 'tkinter', 'Tkinter'],
             datas=extra_files,
             hiddenimports=[],
             hookspath=None,
             runtime_hooks=None)

the important steps being setting extra_files and then specifying it as the datas parameter to Analysis()

I still wanted to call out that this seems to have broken a number of projects.

@celsooliveiraTBDE That issue no attribute __version__ will be fixed in the next release. See #870 and #871.

We also recommend that you import from googleapiclient rather than apiclient.

from googleapiclient import discovery

@jay0lee We moved to declaring the version in the setup.py and using pkg_resources as that is more consistent with what our modern clients do. If you need to use pyinstaller, it looks like there is a workaround. https://stackoverflow.com/questions/34775667/pyinstaller-django-pkg-resources-distributionnotfound-the-django-omnibus

EDIT: Switched the link to the possible solution.

1.8.2 is now released.

Hey guys, I had the same issue with pyinstaller what did the trick for me was to roll back from
google-api-python-client from version 1.8.2 to 1.8.0. I hope this issue gets fixed soon. It wasn't fixed in 1.8.2 as commented due to the fact I was facing the same issue on 1.8.2

python -m pip install google-api-python-client==1.8.0

Thanks

@BoxingStudioGames What error are you seeing?

Here is the error I was getting
pkg_resources.DistributionNotFound: The 'google-api-python-client' distribution was not found and is required by the application manage returned -1
I was able to bypass this error by downgrading the library as commented in my last post.

Sean, I was able to get things working with the latest library by modifying my PyInstaller spec file to include the package metadata, see:

https://github.com/jay0lee/GAM/blob/master/src/gam.spec#L16

Hi Jay, I am going to give your solution a try with the version.
Thanks

Thanks jay0lee. The extended code segment from the .spec file described in https://github.com/jay0lee/GAM/blob/master/src/gam.spec#L16 solved this problem for me. Thanks!!!

Roll back to google-api-python-client 1.8.0 worked for me. Thanks BoxingStudioGames. Wasted a good 3 hours fixing this issue this morning.... with the latest version google-api-python-client.

Thanks @jay0lee, can confirm that your solution works with pyinstaller 4.0 and google-api-python-client 1.10.1!

@DrMantisTobbogan yes, it still works for me with latest versions.

I realize this issue is closed, but in case anyone else is still encountering the error with more recent versions of google-api-python-client, I can report that you can get the error even with google-api-python-client version 1.12.2, at least when using PyInstaller 3.5 on a Windows 10 system in Python 3.6. The solution posted by @jay0lee upthread (https://github.com/googleapis/google-api-python-client/issues/876#issuecomment-625779315), namely to use copy_metadata, solved the problem for me. (And I must say, the error and situation are extremely confusing. I don't know how I would have arrived at _that_ solution myself. I spent at least 2–3 hours doing down a different rabbit hole of things like hidden imports, PyInstaller hooks, etc. I'm extremely thankful for @jay0lee's work on this.)

I see that this issue is closed, but I just ran into this issue on python 3.8.5 with google-api-python-client==1.12.3

Are there any suggestions for overcoming this? The suggested solution of using --hidden-import in the issue referenced above does not resolve this.

@jay0lee 's solution works, but requires importing utils.hooks:

from PyInstaller.utils.hooks import copy_metadata
extra_files = copy_metadata('google-api-python-client')
extra_files.append(('./resource_1', './resource_1'))

@busunkim96 can we please re-open this issue? Seems it's still a problem for many library users.

Yes, we can adopt the strategy added recently in api-core. https://github.com/googleapis/python-api-core/pull/80

i had the same problem
after
from PyInstaller.utils.hooks import copy_metadata
extra_files = copy_metadata('google-api-python-client')
extra_files.append(('./resource_1', './resource_1'))
i have

PyInstaller cannot check for assembly dependencies.
Please install pywin32-ctypes.

pip install pywin32-ctypes

what can i do?

I had this issue with python 3.7 and google-api-python-client 1.12.8.
To solve it I added google-api-python-client as data at the initial pyinstaller line. --add-data has two parameters, SRC;DEST (for Windows), but SRC path searches from the main python scripts folder. So I just got back from my initial directory, then wrote the right path. So it looked like this:

--add-data ../../../../anaconda3/envs/[ENVIRONMENT_NAME]/lib/site-packages/google_api_python_client-1.12.8.dist-info;google_api_python_client-1.12.8.dist-info

Writing the whole path for SRC like "C://.../././" didn't work.

As DEST path, I tried to write a dot, but it didn't work.

One last issue I had before solving was quotes. In the Adding Data Files explanation of PyInstaller, it shows that you need to add quotes. It turns out that when looking for that path, PyInstaller actually shows these quotes as the part of path, so it can't find them (at least it was showing it that way in the spec file). So no need to write the quotes.

Was this page helpful?
0 / 5 - 0 ratings