\( \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.

Saturday, November 23, 2019

Find all required python library inside a project

I was using Python3.8 throughout a project but suddenly one of the required library require Python3.7 to work with, therefore I need to mirgrate everything to another virtual environment.

So I need to know the dependency that I was using in order to do migration, just do the following:

We start off installing
pip install pipreqs
Next cd into working directory and then
[working directory]>pipreqs .
which yields a message:
INFO: Successfully saved requirements file in .\requirements.txt
that looks like the following:

now switch into our virtual environment and pip install them:
pipenv shell
pip install -r requirements.txt
and we are done.

Saturday, November 16, 2019

installation of pytesseract

By pip install tesseract we can install a wrapper of an application based on C++ library. It would not install the tesseract application into our computer. If we run import pytesseract and related API, we will get the following error:
TesseractNotFoundError: tesseract is not installed or it's not in your path

Wednesday, November 13, 2019

Derivation of Important formulas in backward propagation

In Andrew Ng's first course of deep learning one will encounter the following formulas that we need to translate in Python:

Sunday, November 10, 2019

On Logistic Regression

Denote $\sigma(z)$ the sigmoid function defined by $z\mapsto 1/(1+e^{-z})$, for a given feature $X\in \R^n$ the estimator of $\mathbb{P}(y = 1 |X)$  is given by \[\hat y= a =
\sigma(w^TX+b),
\] where $w\in \R^n$ and $b\in \R$.