Provided is a method for solving phase error overcompensation and undercompensation in phase measurement profilometry. Based on an optical three-dimensional measurement method, a raster image is projected to an object surface, raster information modulated by an object surface profile is collected, the height of the object surface is restored, a projector, a CCD camera, an object to be measured and a computer are included, the projector projects a sinusoidal grating, the camera collects the deformed sinusoidal grating after object surface height modulation, the gamma nonlinearity of the projector and the camera and the influence of measuring environment light in the measurement process are considered, when phase errors are compensated in actual measurement, the projector projects completely black images, completely white images four-step phase shift images to the object to be measured, an environment light parameter t is calculated through the collected completely black images and completely white images, an absolute phase phi is calculated through a four-step phase shift phase solution method, the two parameters are substituted into a phase error penalty function, and a phase delta phi used for compensation can be obtained.