Ugandan President Yoweri Museveni is to sign a controversial law which will punish homosexuals with life in prison, a government spokesman said.

"The president is signing the anti-homosexuality bill today at 11 (0800 GMT). He wants to sign it with the full witness of the international media to demonstrate Uganda's independence in the face of Western pressure and provocation," Ugandan government spokesman Ofwono Opondo told Reuters.

Museveni previously rejected the bill, saying that there were other ways to "rescue" homosexuals from their "abnormality", and life imprisonment was not the right method.

However, Museveni changed his mind after consulting with a group of medical experts who claim that "homosexuality is not genetic but a social behaviour".

In a letter to parliament published by independent newspaper Daily Monitor, Museveni said: "The question at the core of the debate on homosexuality is what do we do with an abnormal person? Do we kill him/her? Do we imprison him/her? Or we do contain him/her?"

According to Museveni, homosexuality is caused by either "random breeding" or mercenary reasons, while lesbians are the consequence of "sexual starvation". He believes one of the solutions to eliminating homosexuality in Uganda is to improve economic conditions.

Western countries have strongly criticised the bill and tried to stop it from being signed into law.

President Obama said that the enforcement of this law would represent "a step backward" and it will complicate relations with the US.

Under existing law, anyone found guilty of "carnal knowledge against the order of nature" can already face up to life imprisonment.

Gay activist David Kato was murdered in 2011 after Ugandan weekly Rolling Stone pictured his face and that of another man on its cover under the headline "Hang Them!"

The subhead read: "We shall recruit 100,000 innocent kids by 2012: Homos" and "Parents now face heart-breaks as homos raid schools."

The paper pledged to expose 100 gay people and printed the photographs, names and in some cases addresses of people it claimed were gay.