May to October is considered to be the peak season so we would recommend visiting either in November or in April if you want to avoid the crowds. There is a chance of rain during these months so try to align yourself to clear weather forecasted days.
How To Get To Cusco
From Lima, you can either fly domestically which will take around an hour. Book in advance is recommended if you want to take this route.
In order to see Machu Picchu at your own pace without having to stick to a schedule with others, which is important to avoid the crowds, is to go with a travel agency that provides a round-trip transfer service, train tickets, Machu Picchu entry tickets and plus guided tour.