It is important if you want to receive a good letter of recommendation. You should let the teacher know in advance so that they can properly prepare, go through your records, highlight your strengths, and practically try to 'sell' you to the person you need the letter for. You also need to ask them in advance in case they have other things to do, so that they can make time for you and give you a professional letter that will make you achieve the thing you need to achieve.