Your friend will have no need to leave the US voluntarily to apply for the study permit in Canada.
She will first need to apply to a Canadian Accredited Institution in accordance with the admission standard of the institution. Should the institution admit her application, (typically for international students) she would have to pay for 1 year of tuition up front. Generally the tuition and ancillary fees for 1 year (2 semesters) is between $CAD11000-14000 for international students.
Once tuition is paid the institution will issue a letter of acceptance to her, which she can use to apply for her TRV and Study Permit. She will have to send these applications to Portugal (does not mean she has to go to Portugal to send them).
She must also provide proof of fund for 1 year of living expenses, around $CAD10000-12000.
Once in Canada, she may work on campus without a work permit and she will be eligible to apply for a work permit 6months after her landing date.
But her friend is illegal in the US so she will not be able to apply for the student visa/permit in the US.
http://www.canadainternational.gc.ca/buffalo/imm/visa_temp.aspx?lang=eng#REQUIREMENTSALLREQUIREMENTS FOR TEMPORARY RESIDENT VISA APPLICANTS WITH TEMPORARY STATUS IN THE US
You must provide proof of lawful temporary status in the United States