TAMPA — The bishop of the Roman Catholic Diocese of St. Petersburg issued an apology on his blog Thursday for the decision to allow filming of a raunchy comedy titled “Sex Ed” at the campus of the Sacred Heart Academy in Tampa.

Bishop Robert Lynch said he was awakened Thursday by an email alerting him to a Tampa Tribune story about the filming at the largely deserted academy, which closed two years ago after 81 years in operation.

“I wish to begin by apologizing to all alumni of SHA who like myself are embarrassed and perhaps even mortified by today’s revelations and to assure all it will not happen again,” Lynch wrote in the lengthy Thursday afternoon post.

The diocese had failed to return repeated phone calls from the Tribune seeking comment for its story. Thursday morning, after the story appeared, a spokesman for the diocese contacted the newspaper to say there would be no comment.

One of them was Liana Fox, who graduated in 1964 but still has strong memories of the school — the beautiful campus, the caring nuns who nurtured her academically and emotionally, the many friends she keeps up with to this day.

Fox was upset to read the school is the main location for an R-rated movie featuring raunchy jokes, promiscuity, promotion of birth control, even sex in the convent.

Fox reached out to half a dozen of her fellow alumna.

“We are shocked beyond belief that this could be happening,” she said. “We are so sad, so very sad for this beautiful place.”

Lynch said in his blog post that leaders of the historic Sacred Heart Church downtown, which controls the academy two miles to the north, did not confer with the diocese or read the script as they should have.

“There was no request for assistance from the diocese or its legal counsel and the parish executed the agreement on its own,” Lynch wrote. “Had proper procedures which are in place been followed, this would not have happened and the embarrassment avoided.”

The diocese was alerted last year to the racy tone of the movie but by then the “offensive scenes” had already been filmed, Lynch said. The Rev. George Corrigan, pastor of Sacred Heart and the man who made the decision to close the school for lack of enrollment, was duped about the movie, Lynch wrote.

“While not reading the script, he was shown an outline which he says did not raise any ‘alarms’ and feels he was ‘used.’ He is a very fine pastor.”

Calls to Sacred Heart also were not returned.

“Sex Ed” follows an aspiring math teacher who can only find work overseeing detention at an inner-city public middle school. When he realizes the students know little about sex, he takes it upon himself to teach them — even though he’s a virgin who is as ignorant as they are.

It is scheduled for release in select cities including Tampa on November 7.

The makers of the film denied they duped anyone.

“The film is and always has been titled ‘Sex Ed’ and the outline they were given is accurate,” producer Dori Sperko said in an email to the Tribune on Thursday.

Elayne Schmidt, another producer, whose credits include the forthcoming film “Entourage” and 2001’s “Ali,” said she spoke with a church representative and toured the campus, agreeing to refrain from filming in certain areas.

“It is customary for locations to only request the title and a description of the project,” Schmidt said. “Government organizations will typically request a script, but most other locations do not, so we did not consider this an oversight by the church.”

In the film, the academy goes by the name of Ybor Middle School and no spiritual images are shown.

Sperko called the movie a coming of age story, not a sleazy romp.

“I think audiences and the bishop will be pleasantly surprised by the heart of this film,” she said, “the overall positive message, and the non-partisan approach we have taken to the subject matter.”

She pointed to a review of “Sex Ed” in the Portland Mercury in advance of its world premiere Tuesday Aug. 26 in the coveted opening night film spot at the Portland Film Festival.

“Exactly the sort of movie you want to stumble across on the festival circuit,” the review said.

Some people associated with Sacred Heart said they were delighted at how the school was used.

“I actually find this very interesting. I love seeing Tampa’s film community involved in unique projects like this!” wrote Red Esposito, on the Sacred Heart Academy Alumni Facebook page. “Sounds like a funny plot, too. I wouldn’t call it ‘raunchy.’”

“Renting out the school for that film probably made the church a decent amount of money,” wrote Sarah Hargis. “Even if you don’t like the movie, that’s still a positive.”