Percutaneous puncture has become one of the most widely used minimally invasive techniques in clinical practice due to its advantages of low trauma, quick recovery and easy operation. However, incomplete needle tip movement, tissue barriers and complex distribution of sensitive organs make it difficult to balance puncture accuracy and safety. To this end, this paper proposes a new puncture path planning algorithm for flexible needles, which integrates gravitational guidance, bi-directional adaptive expansion, optimal node selection based on the A* algorithm, and path optimization strategies, with Bi-Rapid-Research Random Trees (Bi-RRTs) at its core, to significantly improve obstacle avoidance capability and computational efficiency. The simulation results of 2D and 3D complex scenes in MATLAB show that compared with the traditional RRT algorithm and Bi-RRT algorithm, the GBOPBi-RRT algorithm achieves significant advantages in terms of path length, computation time and node size. In particular, in the 3D environment, the GBOPBi-RRT algorithm shortens the planning path by 43.21% compared with RRT, 27.47% compared with RRT* and 30.33% compared with Bi-RRT, which provides a reliable solution for efficient planning of percutaneous puncture with flexible needles.