I've switched out of labs before, and it's not as bad as you might think it is. The important thing is to leave on a positive note, have a good excuse for leaving, and ask up front for a letter of rec in the future.
(1) Do your work well, make the PI's job easier, and be completely professional. No lateness. No laziness. No nothing. You want the PI to look at you with respect so that when you leave, you leave behind a good impression that'll influence your LOR.
(2) Leave the lab at a good transition period, giving at least 2 weeks-months notice. By "good transition period" I mean at the start of a new semester, after a poster presentation, or something like that. Thus, your leaving coincides with other changes to the lab environment (graduates leaving, new graduates coming in, etc) and is less noticeable overall. Plus, you avoid making it look like an "out of the blue" decision.
(3) Have a good, legitimate reason to leave. Let the PI know that you have interest in another avenue, or that you're too bust next semester to continue, or some such. Make it a "it's not you, it's me" kind of excuse.
(4) Ask for a future Letter of Rec before you leave and do it in person. It's pretty hard for a PI to say 'no' to your face if you did a good job and once they promise a good LOR in the future, they can't take it back.
J.M.