IT HAS taken 20 years for Richard Attenborough, the actor and director, to get his life of Mohandas K. Gandhi to the screen. Along the way he mortgaged a house, rejected several scripts and had to return periodically to movie roles in "terrible crap" to fill the coffers. Finally, "Gandhi," 3 hours and 20 minutes long and budgeted at $22 million, opens Wednesday at the Uptown.

For the money men, Attenborough says, "The problem was always the same: Who would go to see a movie about a half-naked man sitting on a pillow with a beanstalk in his hand?"

For the devotees of Gandhi, the saint-like leader of India's fight for independence from the British raj, the problem was that it simply couldn't be done. One Indian scholar seriously suggested that the Mahatma be represented on screen "only as a constantly moving sphere of light."

This was a typical reaction to Mohandas K. Gandhi, a British-educated lawyer who, by adopting a loincloth and a policy of nonviolent civil disobedience, became Mahatma Gandhi, the father of Indian nationalism. The subject of 400 biographies, the author of 94 volumes, he seemed to movie makers an unapproachable subject. Jawaharlal Nehru, writing an introduction to one eight-volume biography, said, "No man can write a real life of Gandhi, unless he is as big as Gandhi."

"I had no more than a schoolboy's knowledge of the man when I first read Louis Fischer's biography of him in 1962," Attenborough says, "but I was totally bowled over." Attenborough already had starred in more than 20 British movies and "The Great Escape," an American production, and was disturbed about the silliness of many of his roles. He wanted to produce and direct, and "Gandhi" seemed a worthy project.

"I soon found that everyone Gandhi met he bowled over," Attenborough says. "Lord Louis Mountbatten said that of all the trillions of people he had met, there was only one who struck him as truly great -- right up there with Buddha and Jesus -- and that was Gandhi.' "

The problem was how to bring such a man to the screen as a believable and dramatic character. He was considered a saint, and Attenborough had not dealt with saints: His "O! What a Lovely War" of 1968 was a plea for pacifism, and "A Bridge Too Far" a bloody antiwar film. His previous film biography was "Young Winston," a portrait of the early Churchill, which was equal parts blood and thunder and ambition.

"Gandhi" was to be nothing like those: Early on, Attenborough determined to let his story be guided by his subject's frequent admonition that "my life is my message."

"I didn't want to make a movie about Gandhi's sexual obsessions, or about the Party Congress, or about politics," Attenborough says. "I was guided by Gandhi's example in my selection of incidents for the movie."

Thus "Gandhi" focuses on the passage of a British-educated lawyer in vest and dark suit to beatific hero-monk in loincloth and wire-rimmed spectacles. When things go wrong, he fasts in protest; when soldiers attack his followers, he encourages them to submit to be beaten; and gradually, in his unshakable adherence to this Christ-like policy, the fledgling nation of India rallies around him, and the inflexible British raj finally has to admit Gandhi is no longer a man but an idea, and therefore indestructible.

Within the confines of a single film, and guided by the message of Gandhi's public life, has Attenborough "sanitized" his subject?

"Oh no," Attenborough says, "not at all. Yes, it's pretty clear that as a kid, Gandhi was randy as hell. He was married very young, and when he was 16 or 17 years old, his father was dying. Gandhi was sitting there, massaging his father's head, when he was overcome with a normal urge. So he called to his uncle, and went to his bedroom and awakened his wife. He was making love to her for only a few minutes when his uncle called to him, and Gandhi came tearing down the hall. But before he got there his father had died.

"This incident had a great effect on him, as he says in his autobiography. For the rest of his life he was always trying to rid himself of passion -- not just physical passion, but any passion which might lead to anger."

By Gandhi's own account, he fought a lifelong battle against his own sexuality. When he was in his 70s and deeply depressed over the impending partition of Pakistan, he continued to test himself by having women lie next to him in bed and embrace him. Afterward he would explore whether any sensual feeling had been aroused by the experience.

These and other of Gandhi's attempts to attain brahmacharya -- or spiritual oneness with both sexes -- were controversial, even in his own time. Nirmal Kumar Bose, a former Bengali interpreter of Gandhi's, told the writer Ved Mehta that "after Gandhi's death everyone wanted to suppress all further discussion of the brahmacharya experiments." Bose said he published his "My Days With Gandhi" at his own expense after being advised by the Navajivan Press, which serves as India's arbiter of writing about Gandhi, that his book ought to be about the Mahatma's "great work" and not his sexuality.

The only references to this aspect of Gandhi in Attenborough's film are joking ones. When his wife, Kasturba, is askedif she and Gandhi sleep together, she replies with a smile, "Four times he made a vow." (At the age of 37, Gandhi made a "holy vow" of abstinence.) When her husband is 74, Kasturba is asked if he has broken that vow, and she replies, "Not yet."

One-third of the financing of the film comes from the Indian government, but Attenborough says such choices of incidents were simply a matter of taste. Similarly, Nehru, a character in the film, is seen briefly in public with Mountbatten and his wife. Mountbatten acknowledged publicly that Lady Mountbatten and Nehru had had an affair, but the matter goes unspoken here, and apparently unimplied.

"The film is about Gandhi's life," Attenborough says. "Lord Louis only occupied about 15 months of it."

Attenborough says he was very pleased with the portrayal of Gandhi by Ben Kingsley -- a British actor of Indian heritage who dominates nearly every scene -- and with Rohini Hattangady, who plays Kasturba. He discovered Hattangady in a play in Bombay, and since she spoke no English, all her lines were memorized "parrot-fashion," over a period of 3 1/2 months.

Also featured in the film are Martin Sheen, as an American reporter; Candice Bergen, as the photographer Margaret Bourke-White; and Edward Fox, John Gielgud and Trevor Howard. In an early print of the movie, it closed to very long credits in which Bergen's name came first, and Kingsley's much later. Attenborough agreed with early viewers to whom this seemed absurd, and Kingsley now gets top billing.

Kingsley bears a facial resemblance to Gandhi that Attenborough's camera successfully brings out. Asked if Kingsley's robust physique is at odds with the public image of an emaciated Gandhi, Attenborough replies: "People don't realize that Gandhi was a marvelously good-looking man. We only saw him when he made the newspapers, when of course he was fasting."

Gandhi's life had a wealth of incident, but it also included long periods in jail. And Gandhi, unlike Butch Cassidy, never tried to break out.

"Oh, I know," Attenborough says, laughing. "The fact is he rather enjoyed being in jail. He wrote books there, and he was usually treated well. You won't find him in jail much in the movie for that reason.

"The problem for us all along was the whole concept of nonviolence," he says. "You know, nobody could even get Gandhi to admit he was important. Toward the end of his life he was often pressed to state his credo, but he continually brushed such questions aside. He was against any idea of 'Gandhiism,' saying that rather than there be such a thing, he hoped he would not be remembered at all. 'My life is my message,' was all he would say.

"He maintained, for example, that he was not worthy of the term mahatma, which means 'great soul.' He preferred 'Bapu,' which means simply 'father.'

" 'But Bapu,' he was asked, 'how will we know when you're a mahatma?'

" 'If I die with the words "Oh God" on my lips, then you will know,' was the reply."

So that is how Attenborough chose to begin "Gandhi" -- speaking those words as his last as he was shot to death at close range by a Hindu fanatic in 1948.

"The whole idea that Gandhi led a boring life is ridiculous," Attenborough says. On the contrary, there was so much material that it overwhelmed the limitations of film. Attenborough worked for years with Gerald Hanley, who wrote three successive scripts, none of which Attenborough thought was right. Then Robert Bolt produced two scripts.

"The Bolt scripts were all academic attempts to deal with concepts of eastern mysticism, political machinations and, ultimately, moral judgments regarding Britain's presence in India. He was absolutely fascinated with it all, although of course it had nothing to do with the story we were trying to tell. Had Bob Bolt not had a stroke, he would have started again. But then came Jack Brierly, an expatriate American. What he did was to change what could have been a history lesson into an adventure story. The previous scripts had been mesmerized by the epic, massive events of the period."

"Gandhi," as a story, has certain parallels to that of "Young Winston." Both Churchill and Gandhi made their early reputations in South Africa and went on to be world figures. There, Attenborough believes, the comparison ends.

He has described Churchill as "a lonely, nervous, puny, apprehensive boy who developed into a bumptious, bombastic, ruthless young man." (Always dramatic, though: One of the lines young Churchill speaks in Attenborough's film is, "Wounded under the engine! The rest of you run for cover!"). Gandhi, he has made evident in this movie, was a mahatma with a message the world ignores at its peril.

An RAF gunner-cameraman during World War II, Attenborough finds war idiotic and says the inevitability of "ghastly slaughter of human life" was the point he was trying to make in "A Bridge Too Far" and "O! What a Lovely War." Of the Falklands crisis, he has this to say: "As soon as our bloody prime minister gave permission to sink the Belgrano outside the limit, then naturally the Argentines must rise up and fight back."

To make "Gandhi," he agreed to take no salary, although he says he has a "reasonable position" of more than 10 percent in the finished product, and that for the first time India has agreed to let him take rupees out of the country should there be a profit there. Others in the cast saw the project as more than a movie, too, among them Martin Sheen, who negotiated a normal salary and then donated it to a Biafra fund, according to Attenborough.

"It's terribly important to me that people think about Gandhi," he says. "But it's desperately important, if we're to have a British film industry again, that it get its cost back for the private investors in Britain who've stood behind it."