Species distribution models are widely used in conservation biology and invasive biology. MaxEnt models are the most widely used models among the existing modeling tools. In the MaxEnt modeling process, the default parameters are used most often to build the model. However, these models tend to be overfit. Aiming at this problem, this study uses an optimized MaxEnt model to analyze the impact of past, present and future climate on the distributions of Codonopsis pilosula, an economic species, to provide a theoretical basis for its introduction and cultivation. Based on 264 distribution records and eight environmental variables, the potential distribution areas of C. pilosula in the last interglacial, middle Holocene and current periods and 2050 and 2070 were simulated. Combined with the percentage contribution, permutation importance, and jackknife test, the environmental factors affecting the suitable distribution area of this species were discussed. The results show that the parameters of the optimal model are: the regularization multiplier is 1.5, and the feature combination is LQHP (linear, quadratic, hinge, product). The main temperature factors affecting the distribution of C. pilosula are the annual mean temperature, mean diurnal range, and isothermality. The main precipitation factors are the precipitation seasonality, precipitation in the wettest quarter, and precipitation in the driest quarter, among which the annual average temperature contributes the most to the distribution area of this species. With climate warming, the suitable area of C. pilosula exhibits a northward expansion trend. It is estimated that in 2070, the suitable area of this species will expand to its maximum, reaching 2.5108 million square kilometers. The highly suitable areas of C. pilosula are mainly in Sichuan, Gansu, Shaanxi, Shanxi, and Henan Provinces. Our findings can be used to provide theoretical support related to avoiding the blind introduction of C. pilosula.