Ezekiel 20:7

Then said I unto them, Cast ye away every man the abominations of his eyes, and defile not yourselves with the idols of Egypt: I am the LORD your God.

God commanded Israel while still in Egypt that each person throw away the detestable idols his eyes coveted and stop defiling himself with Egyptian idol worship, on the ground that He is the LORD their God. That command belongs to the time when the few families that had gone down into Egypt had after many years of servitude grown into a large multitude living surrounded by idolatry. By then many had lost the knowledge of the true God and forgotten His law, joining the Egyptians in worshiping the sun, moon, and stars and beasts and images made by men's hands, with everything around them tending to make them forget the living God.

A faithful few still preserved the knowledge of the true God as Maker of heaven and earth, and grieved to see their children daily observing and even taking part in the surrounding abominations, bowing to deities of wood and stone and sacrificing to senseless objects, so in distress they cried to the Lord for deliverance from the Egyptian yoke to a place free from idolatry and its corrupting influence. The command was given before the exodus but was rejected, for many had become corrupted and were content to stay in bondage rather than face the hardships of a journey to a new country, being unwilling to leave Egypt, which shows God's call to obedience and the consequences of rebellion. Therefore God did not deliver them at the first display of signs and wonders before Pharaoh, but overruled events to let Pharaoh's tyrannical spirit fully develop and to display His great power before both the Egyptians and His own people, so as to make His people eager to leave Egypt and choose His service, a course that made the work of Moses much harder.