Consider Galatians 2:16 when thinking about Romans 2:13. These seem contradictory but are not.
Romans 2:13 is a statement that 1) speaks of the fact that salvation is regeneration which results in obedience, and 2) speaks of the fact that under the law, there is condemnation for those who are not perfectly obedient (Galatians 3:10, James 2:10, Matthew 5:48).
If you read from Romans 2:13 all the way down to Romans 3:28, I believe that you will see a progression of thought wherein Paul leaves the idea of being justified by the law and finally comes to the conclusion that no one is justified in the sight of God by law-keeping but that salvation is by faith alone in Jesus Christ. Paul begins the book of Romans with the same understanding as James and progresses in his thought processes to come to realize what he later wrote in Galatians 2:16.
James never came to the realization of this divine revelation because he was killed by Herod before he could think it through (I believe it was in Acts 12).
Galatians 2:16 and Romans 2:13 aren't even speaking about the same law. In Romans 2:13, it is not speaking about the way to become justified, but about something that everyone who will be justified as in common. If we have faith, then we will obey God's Law and if we have faith, then we will be justified, so all those who will be justified have it in common that we are doers of the Law. Obedience is not optional, so it is therefore required.
The need for perfect obedience as always been a fundamental misunderstanding of the goal of the Law and of God's character because it makes God out to be interested in our outward performance when He has always been interested in our hearts, and has always disdained it when His people honored him with their lips while their hearts were far from Him. If someone managed to have perfect outward obedience while their heart was far from God, then that would be worthless and they would be missing the whole point (Philippians 3:8).
The Law itself came with instructions for what to do when people sinned, so perfect obedience was never the requirement. If we needed perfect obedience, then there would be no point in repentance because it would already be too late, yet the consistent message of the prophets up to and including Jesus is to repent from our sins and to return to obedience to the Law, so repentance has always been key. In James 2:1-10, he was speaking to people who had already sinned, so he was not telling them that they needed to have perfect obedience and he was not condemning them, but rather he was encouraging them to repent and to do a better job of obeying the Law more consistently by not showing favoritism.
In Romans 3:21-22, the Law and the Prophets bear witness to the fact that the righteousness of God is given through faith in Christ for all who believe, so this has always been the one and only way to obtain righteousness, and the Law and the Prophets do not bear witness to the righteousness of God being obtained through perfect obedience. James was in full agreement with righteousness being by faith because he approved of Paul's message. In Hebrews 11:7, Noah was listed as an example of faith and in Genesis 6:8-9, it says that he found grace in the eyes of God and that he was a righteous man, so he was declared righteous by grace through faith in the same one and only way as everyone else. In Romans 3:31, our faith does not abolish our need to obey the Law, but rather our faith upholds it.