All perfect praise be to Allaah, The Lord of the Worlds. I testify that there is none worthy of worship except Allah, and that Muhammad, sallallaahu ‘alayhi wa sallam, is His slave and Messenger.
First of all, we appreciate your keenness to uphold what is right and to avoid what might corrupt your religiosity. May Allaah protect you and reward you generously.
As explained earlier in the Fatwas to which we have referred you, it is incumbent on (male) students to lower their gaze from their female teacher. The reasons you mentioned do not justify making it lawful not to lower your gaze from your teacher, given the absence of a considerable need under the Sharee‘ah.
If you can move to another school or class in order to avoid this problem, you are advised to do so; otherwise, you should preoccupy yourself with writing down notes from the teacher's explanation instead of only looking in the book. In order to avoid the headache caused by concentration (on the book), you can divert your gaze to any other direction where your eyes do not fall on the teacher.
Lastly, it should be noted that if you are left to choose between falling into temptation or quitting school, then you should know that preserving your religiosity should be given priority over anything else. Your religion is your most valuable asset so you should hold on to it. Verily, losing one’s religion is the gravest loss of all.
Allaah Knows best.