In a previous post, I derived the modular anomaly using a straightforward computation (although a subtle one). Physicists may be more familiar with the transformation of the Dedekind eta function under S-duality, \begin{equation} \label{Seta} \eta (-1/\tau) = \sqrt{- i \tau} \eta (\tau) \, . \end{equation} This transformation is equivalent to the modular anomaly for the Eisenstein series $E_2$, thanks to the relation \begin{equation} \label{relation} E_2 (\tau) = \frac{12}{\pi i} \frac{\mathrm{d}}{\mathrm{d} \tau} \log \eta (\tau) = \frac{12 \eta ' (\tau)}{\pi i \eta (\tau)} \, . \end{equation} Indeed, taking the differential of (\ref{Seta}), we have $\eta ' (-1/\tau) = \frac{1}{2} \sqrt{-i} \tau^{3/2} \eta (\tau) + \sqrt{-i} \tau^{5/2} \eta ' (\tau)$, and the transformation rule for $E_2$ follows.

Let us then derive the relation (\ref{relation}). We use the well-known expansion for the eta function,
\begin{eqnarray}
\log \eta (\tau) &=& \log \left( q^{1/24} \prod\limits_{k=1}^{\infty} (1-q^k) \right) \\
&=& \frac{1}{24} \log q + \sum\limits_{k=1}^{\infty} \log (1-q^k) \\
&=& \frac{1}{24} \log q - \sum\limits_{k=1}^{\infty} \sum\limits_{n=1}^{\infty} \frac{q^{kn}}{n} \, .
\end{eqnarray}
Then with $\frac{\mathrm{d}}{\mathrm{d} \tau} = 2 \pi i q \frac{\mathrm{d}}{\mathrm{d} q}$ we compute
\begin{eqnarray}
\frac{12}{\pi i} \frac{\mathrm{d}}{\mathrm{d} \tau} \log \eta (\tau) &=& 24 q \frac{\mathrm{d}}{\mathrm{d} q} \log \eta (\tau) \\
&=& 24 q \left( \frac{1}{24 q} - \sum\limits_{k=1}^{\infty} \sum\limits_{n=1}^{\infty} k q^{kn -1} \right) \\
&=& 1 - 24 \sum\limits_{k=1}^{\infty} \sum\limits_{n=1}^{\infty} k q^{kn } \\
&=& 1 - 24 \sum\limits_{N=1}^{\infty} \left( \sum\limits_{k|N} k \right) q^{N } \\
&=& E_2 (\tau) \, .
\end{eqnarray}

Of course, these computations, combined with the derivation presented in the other post, can be seen as a proof of the transformation rule (\ref{Seta}).