The stress analysis of the wellhole surrounding rock and the regular failure of the wellhole has always been a concern for the well builders. Firstly, the Hamilton canonical equations are obtained by using the Hamiltonian variational principle in the sector domain, and the zero eigensolution and nonzero eigensolutions of the homogeneous equation are solved. According to the Hamiltonian operator matrix with the orthogonal eigenfunction system, the special solution form of the nonhomogeneous boundary condition equation is obtained. Then, according to the principle of the same coefficient being equal, the relationship equation between the direction eigenvalue and the angle coefficient is obtained, from which the specific expression of the special solution of the equation can be determined. Furthermore, the analytical solution of the wellhole surrounding rock problem under nonuniform ground stress is obtained by using the linear elastic accumulative principle. Finally, a concrete example is given to compare the finite element method and the symplectic algorithm. The results are consistent, which ensures the accuracy and the reliability of the symplectic algorithm. The relationship between the circumferential stress distribution around the hole and the lateral pressure coefficient is further analyzed.