When tunable diode laser absorption spectroscopy is used to measure the concentration of gas, the second harmonic signal of demodulation is changed due to the influence of temperature change, and the error in concentration measurement is great. In order to solve the problem of large errors in atmospheric quality monitoring equipment due to the change in gas temperature, this paper, based on the tunable semiconductor laser absorption spectroscopy (TDLAS) theory, measured methane gas with 1000 ppm standard gas as the target and selected the central absorption wavelength of 1650 nm. The influence of temperature change on gas injection and the laser absorption spectrometer is studied. A temperature compensation algorithm based on an empirical formula is designed. Firstly, by analyzing the variable temperature test data of the detection module, it is proposed to divide the influence factors of temperature into two parts and study the influence of injection gas temperature and detector temperature, respectively. Secondly, the temperature compensation is carried out by polynomial fitting the concentration inversion results. Finally, according to the compensation effect, a scheme was proposed to compensate the measured gas by applying a constant temperature treatment to the detector at 313 K. After compensation, the average error of the system measurement is reduced from 8.4% to 1.08% when the gas temperature changes from 233 K to 343 K, which effectively reduces the deviation of the measured value caused by the abrupt temperature change. It further improves the accuracy and reliability of measuring gas concentration when gas inspection equipment is working outdoors and has strong practicability.