A 1031 and the above are the only ways to avoid the cap gains.
Keep good books on any rehab work and you can reduce your tax liability there.
In general, however, you need to think about it this way - you purchased TO flip... that is not about living somewhere, that is about a commercial enterprise - a business... i.e. income. THAT is why it is taxed as income... it is income! Makes sense, right? That's the spirit of the law, hopeful the letter of the law matches.