By doing it with sincerity and without an ulterior motive.
Unfortunately, the latter especially, rarely exists.
plus there's a difference between a compliment and being Pervy.
I'm sure Laura will correct me if I'm wrong, but if a male colleague complimented her hair, or clothes in a sincere way it would be fine.
But basically saying "YOU'RE ATTRACTIVE!" is weird.
Definitely.
It's a weird compliment at the best of times. But we'd just met, he called me attractive; it's creepy.
And as I said, it wasn't because he thought I was attractive, it was because he was trying to sell me something. Which just makes it even more annoying.