The radiation of stars heats dust grains in the diffuse interstellar medium and in star-forming regions in galaxies. Modelling this interaction provides information on dust in galaxies, a vital ingredient for their evolution. It is not straightforward to identify the stellar populations heating the dust, and to link attenuation to emission on a sub-galactic scale. Radiative transfer models are able to simulate this dust-starlight interaction in a realistic, three-dimensional setting. We investigate the dust heating mechanisms on a local and global galactic scale, using the Andromeda galaxy (M31) as our laboratory. We perform a series of panchromatic radiative transfer simulations of Andromeda with our code SKIRT. The high inclination angle of M31 complicates the 3D modelling and causes projection effects. However, the observed morphology and flux density are reproduced fairly well from UV to sub-millimeter wavelengths. Our model reveals a realistic attenuation curve, compatible with previous, observational estimates. We find that the dust in M31 is mainly (91 % of the absorbed luminosity) heated by the evolved stellar populations. The bright bulge produces a strong radiation field and induces non-local heating up to the main star-forming ring at 10 kpc. The relative contribution of unevolved stellar populations to the dust heating varies strongly with wavelength and with galactocentric distance.The dust heating fraction of unevolved stellar populations correlates strongly with NUV-r colour and specific star formation rate. These two related parameters are promising probes for the dust heating sources at a local scale.