It happened after 9:00 a.m. Monday at the De La Salle In Town School at 25 South Van Pelt Street in Center City.
The director of the school, which is a day treatment center for adjudicated youth run by the Philadelphia Archdiocese, told Action News the student set off a metal detector while entering the building. They found the gun in his jacket pocket.
Philadelphia Police responded to the scene and recovered a .22 caliber pistol with 9 rounds from the 17-year-old male student.
"We were quite happy that the metal detection system worked and the student I think was very cooperative with us when we identified it," said Charles Gaus, director of the school.
The student was taken into custody and police say he is facing multiple charges.
It is unclear if the gun was loaded.
Police have also told Action News that the suspect has an arrest history for drug charges.
No one was injured. Officials say he made no threats against anyone.
The De La Salle In Town School has suspended the student.