If you have some sort of resident status (a one-year visa is typically enough for example), then you are in fact supposed to apply in Canada and nowhere else.
If you are not a resident, you should generally apply in the consulate serving your place of usual residence. But the visa code gives consulate a bit of leeway and they can always accept to process your application if you provide a good reason.
See also Can we apply for a Schengen tourist visa while visiting another country on a short-stay visa?Can we apply for a Schengen tourist visa while visiting another country on a short-stay visa? and Can I get an appointment at a French consulate different than the one assigned to my state?Can I get an appointment at a French consulate different than the one assigned to my state? for details on the regulation and some related situations.