\( \newcommand{\N}{\mathbb{N}} \newcommand{\R}{\mathbb{R}} \newcommand{\C}{\mathbb{C}} \newcommand{\Q}{\mathbb{Q}} \newcommand{\Z}{\mathbb{Z}} \newcommand{\P}{\mathcal P} \newcommand{\B}{\mathcal B} \newcommand{\F}{\mathbb{F}} \newcommand{\E}{\mathcal E} \newcommand{\brac}[1]{\left(#1\right)} \newcommand{\abs}[1]{\left|#1\right|} \newcommand{\matrixx}[1]{\begin{bmatrix}#1\end {bmatrix}} \newcommand{\vmatrixx}[1]{\begin{vmatrix} #1\end{vmatrix}} \newcommand{\lims}{\mathop{\overline{\lim}}} \newcommand{\limi}{\mathop{\underline{\lim}}} \newcommand{\limn}{\lim_{n\to\infty}} \newcommand{\limsn}{\lims_{n\to\infty}} \newcommand{\limin}{\limi_{n\to\infty}} \newcommand{\nul}{\mathop{\mathrm{Nul}}} \newcommand{\col}{\mathop{\mathrm{Col}}} \newcommand{\rank}{\mathop{\mathrm{Rank}}} \newcommand{\dis}{\displaystyle} \newcommand{\spann}{\mathop{\mathrm{span}}} \newcommand{\range}{\mathop{\mathrm{range}}} \newcommand{\inner}[1]{\langle #1 \rangle} \newcommand{\innerr}[1]{\left\langle #1 \right \rangle} \newcommand{\ol}[1]{\overline{#1}} \newcommand{\toto}{\rightrightarrows} \newcommand{\upto}{\nearrow} \newcommand{\downto}{\searrow} \newcommand{\qed}{\quad \blacksquare} \newcommand{\tr}{\mathop{\mathrm{tr}}} \newcommand{\bm}{\boldsymbol} \newcommand{\cupp}{\bigcup} \newcommand{\capp}{\bigcap} \newcommand{\sqcupp}{\bigsqcup} \newcommand{\re}{\mathop{\mathrm{Re}}} \newcommand{\im}{\mathop{\mathrm{Im}}} \newcommand{\comma}{\text{,}} \newcommand{\foot}{\text{。}} \)

Sunday, November 24, 2019

Pyinstaller --- executable file with Google API --- obstacles I have:

  • The first one we come across in many cases should be:
    pkg_resources.DistributionNotFound: The [distribution name] distribution was not found 
    
    where [distribution name] is among $\{$google-*-core, google-cloud-* $\}$ for various possible *. The first strategy is reinstallation. To somebody reinstalling the package in trouble will do. To me, I completely reinstall Python from 3.8 to just 3.7.5.

    And in order to keep projects' dependency separate enough, the first package I download is pipenv and installation of the second first package is done in pipenv shell.
  • No module named [sth], to me [sth]'s are respectively google and then google.cloud. I have tried to edit .spec to include these packages as hiddenimports then pyinstaller xxx.spec.

    If problem persists, try to pip show [missing package] to get the location of problematic package, then add this location to pathex. In my case reinstalling Python gets rid of all the problems in this bullet point.
  • After reinstallation, we have a very clean environment, the only problem left to me is again the google-cloud-vision, which is solved by adding hook-google.cloud.py the following

       data += copy_metadata('google-cloud-vision')

  • After we get through all the trouble and successfully build an executable file, we may next encounter :
    Error: Exception in 'grpc._cython.cygrpc.ssl ............ pem_root_certs != nullptr
    To this we create a hook-grpc.py and type the following:
    from PyInstaller.utils.hooks import collect_data_files
    datas = collect_data_files('grpc')
    
At this point my journey battling with pyinstaller and google api is done, which spent me half of a day to get around all of these problems..., hope this article helps.

No comments:

Post a Comment