  Using canonical transformations we obtain localized (in space) exact
solutions of the nonlinear Schr\"odinger equation (NLSE) with space and time
modulated nonlinearity and in the presence of an external potential depending
on space and time. In particular we obtain exact solutions of NLSE in the
presence of a number of non Hermitian $\mathcal{PT}$ symmetric external
potentials.
