A knife is a contact weapon, for it to be used you either have to let your attacker come into contact range or close with the attacker, neither is a very good idea. You have to remember that if you can touch your attacker then the attacker can touch you and is more likely to be (a) skilled in violence and (b) willing to perform violence.
Pepper spray is a distance weapon and can be used while maintaining distance, ie it can be used while retreating. Good sprays are effective up to 20 feet and are capable of several full power blasts. Distance is alway an advantage to the victim and you want to create as much as possible. Should the attack take place at close range a spray from point blank range into the face is devastating, the spray has enough velocity to do serious damage to the eyes and getting a mouthful or lungful is very unwelcome also.
Of course awareness is key as well, attacker don't go after someone who is alert, scanning their surroundings, paying attention to what is happening around them, they don't need to. There are plenty of people who play the role of victim very well, I see them all the time. They are the ones walking alone after dark with their IPod earbuds in, daydreaming as they walk along...these are the ones attackers prefer.