Well let me just state that my input on this subject would present my own understanding and I am not sure if it is 100 percent accurate.
We as humans have free will to do things or not to do. There are 2 ways one can follow. One is worshiping God and obeying the commandments and doing good deeds, the other way is going against the commandments or doing "bad" things and that is what I call sin.
We as humans are in constant fight with ourselves and try hard not to sin. Prohpets are humans. They also have desires.
Now let us go back when I said there are two ways. The idea that I said there are two ways is because God is telling us how to avoid sins. God is providing us with a way which is worshiping him. The more you worship Allah and do good deeds, the more you are in strength to follow the commandments and the more strength you will have to fight your "evil" desires. Because that will always remind you of Allah, heaven, rewards, and what will be waiting for you.
Prophets are people. They have desires. However, they are sharing the message of worshiping God. They are people who used to live the message they are sharing. The more you walk in that way, the less sins you would do.
But still prophets are humans.
For example, once a blind man came to the prophet Muhammad peace be upon him and wanted to ask him a question. But the messenger frowned and turned away, I am not sure of the reason why. But some verses were revealed for our prophet on that incident.
80
1 The Prophet frowned and turned away
2 Because there came to him the blind man, [interrupting].
3 But what would make you perceive, [O Muhammad], that perhaps he might be purified
4 Or be reminded and the remembrance would benefit him?
Another example is that Adam ate from the tree,
Also Sahih International
11 47 [Noah] said, "My Lord, I seek refuge in You from asking that of which I have no knowledge. And unless You forgive me and have mercy upon me, I will be among the losers."
However, all the prophets sins were minors. Not like the way most people sin because prophets used to live the message they shared with people. They are the most who worship God truly and do God deeds and be patient. They used to repent and ask for forgiveness directly. Besides they were chosen to be prophets and hence the information about who God is they provide us with is not something questioned. The only information we were given is what God wanted us to know and there could be no mistake otherwise they wouldn't have been chosen to be prophets.
Many scholars say on this that there sins are actually slight mistakes and forgetting or not knowing. So when it comes to telling us who God is and how we should follow God, yes they are perfect and they are people of example.