How do you re-create one of the most famous neighborhoods in the world during its most infamous era? When you’re talking about Times Square in 1971, you have to look far and wide, especially now that the area is sanitized and sterilized (save for Elmos and desnudas).

“The Deuce,” premiering Sunday on HBO, is a drama about the rise of the pornography industry in 1971 in New York City and how mobsters, pimps and prostitutes all tried to cash in. The show takes its title from the old nickname given to West 42nd Street (a k a “forty-deuce”) between Seventh and Eighth avenues.

Production designer Beth Mickle went to 30 locations in New York City’s five boroughs, searching for a place where hookers could prowl the streets under the neon marquees of classic porno theaters and peep shows.

Her quest ended in Washington Heights, on Amsterdam Avenue between West 163rd and West 165th streets. This stretch of delis, salons and storefront churches surprisingly checked a lot of boxes on Mickle’s list.

“[The street] has six lanes, with parking lanes, the same width as 42nd Street,” said Mickle. The sidewalks uptown were almost a perfect match: 20 feet for the real 42nd Street, 19 feet on Amsterdam Avenue. The entire street was “almost the same exact scale.”

Other musts included older store frontage, no trees and no scaffolding, something that is nearly impossible to find in Manhattan today. Washington Heights was also attractive because of its lack of boxy chain stores and glass condos. In other locations, she and her location manager kept finding “Foot Lockers and Duane Reades. [This stretch of Amsterdam Avenue] didn’t have completely new Chase banks,” Mickle explained.

Treating the two blocks as a blank slate, she and her team created subway station exits and turned buildings into arcades, movie theaters and porn stores — adding plenty of litter to hit just the right ugly, ’70s NYC notes.

Here’s how “The Deuce” made bad old Times Square come alive again in Washington Heights.

PLAYLAND

In the ’70s, the West 42nd St. arcade — a haven for pinball wizards — was a hangout for a prostitution ring of young teen boys.

To revive Playland for background scenes, Mickle set-dressed La Nueva Juquila, a small Mexican restaurant. She kept the red exterior and added placards for photo IDs (which the real Playland displayed), as well as neon advertisements reading “XXX” and “Girls Girls Girls.” All that decoration did double duty: “We did window signage and curtains to block the tables and chairs inside,” Mickle explained.

She commissioned a neon Playland marquee that looked exactly like the period original, and for the final touch, trash was strewn about.

ABC ELECTRONICS & THE LIONEL HOTEL

The Eddy Food Center bodega was converted into an appliance store thanks to mood lighting and a few sign swaps, while the original blue-and-white awning — advertising sandwiches and sodas — stayed in place.

Central to the plot of “The Deuce” is the building next door, which doubles as the Lionel Hotel. This is the fleabag where Candy and the other prostitutes take their tricks and where Frankie Martino, one of the twin brothers played by James Franco, lives.

“We used the stoop and the hallway,” Mickle said of the apartment building. “We built a cove that hides the mailboxes and cleared out the trash bins. We also built a spot for the hotel keeper and his desk.”

REGIS CAMERA

The Centro Cultural Deportivo Dominicano — a popular spot for Friday-night salsa dancing — provided the perfect backdrop for a camera store where “Deuce” prostitutes loiter hopefully.

The first thing the Mickle team did was replace the brown double doors with white ones. To create the illusion of a well-stocked shop, “We put up a glass storefront and filled it with camera equipment. We made a backing wall just 10 feet into the storefront so it would block everything behind it,” Mickle said. Behind that, the cultural center’s auditorium doubled as the craft-services cafeteria for cast and crew.

The building’s other door was hidden behind a poster for a record shop.

SUPREME BOOKS & PORN

Mickle and her team turned restaurant Don Panchito into Supreme Books, a porn shop owned by character Fat Mooney (E.J. Carroll) which gets raided by cops. “We built in the shelving and stocked it with porn paraphernalia,” said Mickle. “We made all the porn magazines.” Producer Nina K. Noble explained, “You can’t use real magazines [from the 1970s]. If any of those models were underage, it would be a problem.”

CHARACTERS’ REAL-LIFE INSPIRATIONS

Vincent & Frankie Martino (James Franco): The owner of the show’s Hi-Hat bar, Vincent, is based on a guy who owned the Tin Pan Alley bar, a hangout for artists such as photographer Nan Goldin. “He had a ne’er-do-well [twin] brother” — known as Frankie in the show — said Pelecanos, who met with the real Vincent (whose surname is withheld) shortly before the man’s death.

Sandra Washington (Natalie Paul): Washington is a journalist who hangs out in the bars where the “Deuce” hookers spend downtime between “appointments.” She is based on Gail Sheehy, a writer who covered the Times Square prostitution scene for New York magazine in 1972. She followed that up with a book and a TV movie, “Hustling.” Pelecanos changed Sheehy’s race and her employer to the Amsterdam News, one of the oldest African-American-owned newspapers in the country.

Eileen “Candy” Merrell (Maggie Gyllenhaal): Candy is based on a couple of women, including the porn actress and director Candida Royalle , who made female-centric films designed to oppose the typical misogynistic takes of the genre. (Royalle died in 2015, at age 64, of ovarian cancer.) Another inspiration, Pelecanos told The Post, was a prostitute who frequented Times Square and was a bartender at the bar owned by the real inspiration for James Franco’s twin-brother character, Vincent. “A lot of the stuff that happens to her in the show is real. Like the rat on her shoulder in the theater [when she’s servicing a client],” he said.