Objective: Ultrasound-guided puncture often faces challenges in visualizing the needle. Needle positioning systems can provide real-time needle position information to the doctor. Due to its large spatial footprint and limited portability, positioning methods based on external tracking systems have not been widely adopted. In this study, we developed a multipole magnetic needle positioning method for ultrasound-guided puncture, aiming to maintain the portability advantages of ultrasound while achieving good positioning accuracy. Methods: A magnetic sensor array is installed within the ultrasound probe. The needle continuously generates a specific magnetic field through multipole magnetization. A positioning algorithm combining magnetic gradient tensor method and direct inversion method can accurately locate the position of the needle. To improve localization accuracy, an environmental magnetic field identification method based on machine learning is employed. Results: The environmental magnetic field identification method achieved an accuracy, precision, recall, and F1 score of 98.38%, 98.70%, 98.06%, and 98.38%, respectively. During the puncture process, the maximum positioning errors of tip and direction are respectively 3.49 mm and 4.93 degrees. In the phantom puncture experiment, novices who use our positioning system have a higher first-time success rate. Conclusion: This needle positioning method can accurately locate the multipole magnetic needle. The ultrasound-guided puncture system using this method can display the position of the puncture needle in real time. It can help novices complete puncture tasks more easily. Significance: This system provides a new approach to the design of ultrasound-guided puncture navigation systems. The positioning algorithm can also be applied to locate other elongated ferromagnetic objects.