Phase drift is the main source of errors for phase encoding quantum ke y distribution (QKD) system, and it is an important factor influencing the practical applications of the syst em.At present,there are some kinds of methods to solve the phase drift problem.T hey may reduce the phase drift to some extent,but they also have many shortcomings,such as large amount of calculation,low accuracy an d complex system.In this paper, we put forward a kind of active phase compensation method based on least squares .Scanning a small number phase points under the condition of a single photon,we can get phase compensation parameters by applying the least square algorithm.Th e experimental results show that the method gains phase drift parameter in short er time with less computational cost to complete the real-time active com pensation.It can improve the QKD system′s performance and efficiency to a certain extent.