You can - but it's harder to be approved since it's more difficult to demonstrate strong ties to your home country. It's better to apply while outside of Canada.
Also, if you apply while inside of Canada, your application cannot be processed through a visa office in Canada. It must either be sent to the visa office responsible for your home country or the US.