The implementation of π production in the Liège intranuclear cascade model (INCL4) for spallation reactions is revisited to alleviate the overestimate of the π yield. Three modifications are proposed for this purpose: a better πN cross section at high energy, the introduction of a π average potential, and the modification of the average mass of the resonance. The π potential is determined from a global fit of a set of data bearing on π production in proton-induced reactions, on π -nucleus and absorption cross sections, and on proton production in π -induced reactions. The resulting π potential is poorly determined in the nuclear interior and agrees with the phenomenological optical-model potentials in the surface region. With these modifications, the predictions of the INCL4 model concerning π production cross sections in proton-induced reactions are considerably improved. Predictions of the improved version for π -nucleus reaction and absorption cross sections and for proton, residue, and fission cross sections in π -induced reactions are also presented and shown to give reasonably good agreement. Neutron production and some aspects of fission in π -induced reactions are also investigated and reasonably well predicted. Effects on the modifications on observables, which are not directly linked with π 's, such as the neutron yield and the residue mass and charge spectra in proton-induced reactions are also investigated and shown to improve the description of these observable quantities. Several results on π production and the relative insentivity to the π potential in the nuclear interior are shown to be consistent with the fact that most π 's are not produced in early collisions. Importance of rescattering in π absorption on nuclei is also pointed out. A comparison is made with the so-called -hole model. Residual discrepancies are identified and are interpreted as due to the lack of π interaction with two nucleons at low energy, to the neglect of quantum motion effects, and to a possible underestimate of rescattering.