Why is there a Pilot Shortage?

It always astounds me how safe aviation has become over the past 10-20 years. Even with commercial aviation growing at steady rate of 7% annually, the number of accidents per million flights has dropped to an all time low of 2.4 per million departures.