Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
265 views
in Technique[技术] by (71.8m points)

python - convertng py to exe using pyinstaller with googleapiclient

Hi I have a problem with converting my python file to exe. I have a error:

  File "s.py", line 6, in <module><br>
ModuleNotFoundError: No module named 'googleapiclient'<br>
[17760] Failed to execute script s

Line 6 is:
from googleapiclient.discovery import build

When i install googleapiclient in the desame folder where the python file is i get this thing:

Traceback (most recent call last):
  File "c:program files (x86)python38-32libsite-packagesauto_py_to_exepackaging.py", line 131, in package
    run_pyinstaller()
  File "c:program files (x86)python38-32libsite-packagesPyInstaller\__main__.py", line 114, in run
    run_build(pyi_config, spec_file, **vars(args))
  File "c:program files (x86)python38-32libsite-packagesPyInstaller\__main__.py", line 65, in run_build
    PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
  File "c:program files (x86)python38-32libsite-packagesPyInstalleruildinguild_main.py", line 725, in main
    build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
  File "c:program files (x86)python38-32libsite-packagesPyInstalleruildinguild_main.py", line 672, in build
    exec(code, spec_namespace)
  File "C:UserskompuAppDataLocalTempmp3b0mqik9s.spec", line 6, in <module>
    a = Analysis(['C:/Users/kompu/Desktop/w/s.py'],
  File "c:program files (x86)python38-32libsite-packagesPyInstalleruildinguild_main.py", line 242, in __init__
    self.__postinit__()
  File "c:program files (x86)python38-32libsite-packagesPyInstalleruildingdatastruct.py", line 160, in __postinit__
    self.assemble()
  File "c:program files (x86)python38-32libsite-packagesPyInstalleruildinguild_main.py", line 420, in assemble
    self.graph.process_post_graph_hooks()
  File "c:program files (x86)python38-32libsite-packagesPyInstallerdependanalysis.py", line 367, in process_post_graph_hooks
    module_hook.post_graph()
  File "c:program files (x86)python38-32libsite-packagesPyInstallerdependimphook.py", line 447, in post_graph
    self._load_hook_module()
  File "c:program files (x86)python38-32libsite-packagesPyInstallerdependimphook.py", line 408, in _load_hook_module
    self._hook_module = importlib_load_source(
  File "c:program files (x86)python38-32libsite-packagesPyInstallercompat.py", line 598, in importlib_load_source
    return mod_loader.load_module()
  File "<frozen importlib._bootstrap_external>", line 462, in _check_name_wrapper
  File "<frozen importlib._bootstrap_external>", line 962, in load_module
  File "<frozen importlib._bootstrap_external>", line 787, in load_module
  File "<frozen importlib._bootstrap>", line 265, in _load_module_shim
  File "<frozen importlib._bootstrap>", line 702, in _load
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 783, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "c:program files (x86)python38-32libsite-packages\_pyinstaller_hooks_contribhooksstdhookshook-google.api_core.py", line 14, in <module>
    datas = copy_metadata('google-api-core')
  File "c:program files (x86)python38-32libsite-packagesPyInstallerutilshooks\__init__.py", line 977, in copy_metadata
    dist = pkg_resources.get_distribution(package_name)
  File "c:program files (x86)python38-32libsite-packagespkg_resources\__init__.py", line 482, in get_distribution
    dist = get_provider(dist)
  File "c:program files (x86)python38-32libsite-packagespkg_resources\__init__.py", line 358, in get_provider
    return working_set.find(moduleOrReq) or require(str(moduleOrReq))[0]
  File "c:program files (x86)python38-32libsite-packagespkg_resources\__init__.py", line 901, in require
    needed = self.resolve(parse_requirements(requirements))
  File "c:program files (x86)python38-32libsite-packagespkg_resources\__init__.py", line 787, in resolve
    raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'google-api-core' distribution was not found and is required by the application

I was installing and uninstalling, upgrading itp. googleapiclient several times. Idk what can I do more.
Please help me guys.

question from:https://stackoverflow.com/questions/65935097/convertng-py-to-exe-using-pyinstaller-with-googleapiclient

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I have also encountered this error before. To fix this you need to go to build your exe, then go to site-packages folder inside lib folder, so for me its:

C:Users - Your User - AppDataLocalProgramsPythonPython39Libsite-packages

There you need to locate your module - googleapiclient - (it should be a folder) and copy it to your dist folder where the exe is stored.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...