The program that authenticates with PyDrive does not work properly when it is exeged with PyInstaller.

Asked 1 years ago, Updated 1 years ago, 302 views

I used PyDrive to create a program to download files from my Google drive to my desktop and verified that they worked.

However, when I made this file exe, it didn't work as expected, and it closed immediately after the window stood up for a moment.Could you please let me know if there are any reasons or items I should check?

Also, Python version is 3.6 and if it is simple with input and print, it could be exe without any problems.
Is it impossible to exe py files including PyDrive authentication in the first place?

Py File Contents

#Import required libraries
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive  
file_id='XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

# perform OAuth authentication
gauth=GoogleAuth()
gauth.CommandLineAuth()
drive=GoogleDrive(gauth)

# Download files from Google Drive
f=drive.CreateFile({'id':file_id})
f.GetContentFile('abc.bat')

The command for exeization is py-m PyInstaller dl.py --onefile, and the results are as follows:
pThe name of the py file is dl.py
*exe conversion is performed at the command prompt
  

42 INFO:PyInstaller: 3.6
    142 INFO: Python: 3.6.8
    142 INFO: Platform: Windows-10-10.0.18362-SP0
    144 INFO:wrotte C:\Users\admin\Desktop\dl.spec
    145 INFO—UPX is not available.
    150 INFO—Extending PYTHONPATH with paths
    ['C:\\Users\\admin\\Desktop', 'C:\\Users\\admin\\Desktop']
    151 INFO—Checking Analysis
    152 INFO—Building Analysis because Analysis-00.toc is non existent
    152 INFO: Initializing module dependency graph...
    159 INFO: Caching module graph hooks...
    175 INFO: Analyzing base_library.zip...
    3614 INFO: Caching module dependency graph...
    3690 INFO:running analysis -00.toc
    3693 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
      required by C:\Users\admin\AppData\Local\Programs\Python\Python36\python.exe
    3778INFO: Analyzing C:\Users\admin\Desktop\dl.py
    3976 INFO: Processing pre-safe import module hook mix.moves
    4494 INFO: Processing pre-find module path hook distutils
    4496 INFO:distributing to non-venv dir'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python36\\lib'
    5973 INFO: Processing module hooks...
    5973 INFO: Loading module hook "hook-certifi.py" ...
    5976 INFO: Loading module hook "hook-distutils.py" ...
    5977 INFO: Loading module hook "hook-encodings.py" ...
    6149INFO: Loading module hook "hook-google.api_core.py" ...
    6152 INFO: Loading module hook "hook-httplib2.py" ...
    6154 INFO: Loading module hook "hook-pkg_resources.py" ...
    6724 INFO: Processing pre-safe import module hook win32 com
    6810 INFO: Excluding import '__main__'
    6812 INFO —Removing import of __main__from module pkg_resources
    6812 INFO: Loading module hook "hook-pydoc.py" ...
    6813 INFO: Loading module hook "hook-pythoncom.py" ...
    7190 INFO: Loading module hook "hook-pywintypes.py" ...
    7571 INFO: Loading module hook "hook-sysconfig.py" ...
    7573 INFO: Loading module hook "hook-win32com.py" ...
    8063 INFO: Loading module hook "hook-xml.py" ...
    8296 INFO:Looking for ctypes DLLs
    8308 INFO: Analyzing run-time hooks...
    8312 INFO: Including run-time hook 'pyi_rth_multiprocessing.py'
    8316 INFO: Including run-time hook 'pyi_rth_certifi.py'
    8318 INFO: Including run-time hook 'pyi_rth_pkgres.py'
    8319 INFO: Including run-time hook 'pyi_rth_win32comgenpy.py'
    8327 INFO: Looking for dynamic libraries
    8748 INFO: Looking for eggs
    8748 INFO: Using Python library C:\Users\admin\AppData\Local\Programs\Python\Python36\python36.dll
    8749 INFO: Found binding redirects:
    []
    8759INFO:Warnings write to C:\Users\admin\Desktop\build\dl\warn-dl.txt
    8929 INFO: Graph cross-reference write to C:\Users\admin\Desktop\build\dl\xref-dl.html
    8967 INFO: checking PYZ
    8967 INFO: Building PYZ because PYZ-00.toc is non existent
    8968INFO: Building PYZ (ZlibArchive) C:\Users\admin\Desktop\build\dl\PYZ-00.pyz
    10427INFO: Building PYZ (ZlibArchive) C:\Users\admin\Desktop\build\dl\PYZ-00.pyz completed successfully.
    10468 INFO:checking PKG
    10468 INFO—Building PKG cause PKG-00.toc is non existent
    10469 INFO: Building PKG (Carchive) PKG-00.pkg
    13745INFO: Building PKG (Carchive) PKG-00.pkg completed successfully.
    13749INFO: Bootloader C:\Users\admin\AppData\Local\Programs\Python\Python36\lib\site-packages\PyInstaller\bootloader\Windows-64bit\run.exe
    13750 INFO:checking EXE
    13750 INFO—Building EXE cause EXE-00.toc is non existent
    13750 INFO—Building EXE from EXE-00.toc
    13751INFO:Appending archive to EXEC:\Users\admin\Desktop\dist\dl.exe
    13768INFO: Building EXE from EXE-00.toc completed successfully.

The results of executing the exe file at the command prompt are as follows:

 C:\Users\admin\Desktop>dl.exe
Traceback (most recent call last):
  File "C:\Users\admin\Desktop\dl.py", line 2, in <module>
    from pydrive.auth import GoogleAuth
  File "<frozen importlib._bootstrap>", line 971, in_find_and_load
  File"<frozen importlib._bootstrap>", line 955, in_find_and_load_unlocked
  File"<frozen importlib._bootstrap>", line 665, in_load_unlocked
  File "C:\Users\admin\AppData\Local\Programs\Python\Python36\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 623, inexec_module
    exec(bytecode, module.__dict__)
  File "C:\Users\admin\AppData\Local\Programs\Python\Python36\lib\site-packages\pydrive\auth.py", line 7, in <module>
    from apicclient.discovery import build
  File "<frozen importlib._bootstrap>", line 971, in_find_and_load
  File"<frozen importlib._bootstrap>", line 955, in_find_and_load_unlocked
  File"<frozen importlib._bootstrap>", line 665, in_load_unlocked
  File "C:\Users\admin\AppData\Local\Programs\Python\Python36\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 623, inexec_module
    exec(bytecode, module.__dict__)
  File "C:\Users\admin\AppData\Local\Programs\Python\Python36\lib\site-packages\picclient\_init__.py", line 8, in <module>
    from googleapiclient import discovery
  File "<frozen importlib._bootstrap>", line 971, in_find_and_load
  File"<frozen importlib._bootstrap>", line 955, in_find_and_load_unlocked
  File"<frozen importlib._bootstrap>", line 665, in_load_unlocked
  File "C:\Users\admin\AppData\Local\Programs\Python\Python36\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 623, inexec_module
    exec(bytecode, module.__dict__)
  File "C:\Users\admin\AppData\Local\Programs\Python\Python36\lib\site-packages\googleapicclient\discovery.py", line 67, in<module>
    from googleapiclient.http import build_http
  File "<frozen importlib._bootstrap>", line 971, in_find_and_load
  File"<frozen importlib._bootstrap>", line 955, in_find_and_load_unlocked
  File"<frozen importlib._bootstrap>", line 665, in_load_unlocked
  File "C:\Users\admin\AppData\Local\Programs\Python\Python36\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 623, inexec_module
    exec(bytecode, module.__dict__)
  File "C:\Users\admin\AppData\Local\Programs\Python\Python36\lib\site-packages\googleapicclient\http.py", line 67, in<module>
    from googleapiclient.model import JsonModel
  File "<frozen importlib._bootstrap>", line 971, in_find_and_load
  File"<frozen importlib._bootstrap>", line 955, in_find_and_load_unlocked
  File"<frozen importlib._bootstrap>", line 665, in_load_unlocked
  File "C:\Users\admin\AppData\Local\Programs\Python\Python36\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 623, inexec_module
    exec(bytecode, module.__dict__)
  File "C:\Users\admin\AppData\Local\Programs\Python\Python36\lib\site-packages\googleapicclient\model.py", line 36, in <module>
    _LIBRARY_VERSION = pkg_resources.get_distribution("Google-api-python-client").version
  File "C:\Users\admin\AppData\Local\Programs\Python\Python36\lib\site-packages\pkg_resources\_init__.py", line 479, inget_distribution
    dist=get_provider(dist)
  File "C:\Users\admin\AppData\Local\Programs\Python\Python36\lib\site-packages\pkg_resources\_init__.py", line 355, inget_provider
    return working_set.find(moduleOrReq) or require(str(moduleOrReq))[0]
  File "C:\Users\admin\AppData\Local\Programs\Python\Python36\lib\site-packages\pkg_resources\_init__.py", line 898, require
    needed = self.resolve(parse_requirements(requirements))
  File "C:\Users\admin\AppData\Local\Programs\Python\Python36\lib\site-packages\pkg_resources\_init__.py", line 784, in resolve
    raise DistributionNotFound(req,requires)
pkg_resources.DistributionNotFound: The 'Google-api-python-client' distribution was not found and is required by the application
[21036] Failed to execute script dl
C:\Users\admin\Desktop>

Executing error message pkg_resources.DistributionNotFound: The 'Google-api-python-client' distribution was not found and is required by the application
I have verified that the google-api-python-client has already been installed/upgraded.
I looked for it on other sites, but I couldn't find a solution.

python python3 google-api pyinstaller

2022-09-30 21:50

1 Answers

Try running from a command prompt.I think there is probably an error in that part.


2022-09-30 21:50

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.