Unlicensed drivers and most non-EU citizens are required to take a Spanish driving test, (written theory and practical), in order to obtain a Spanish licence. Helpfully, in larger cities and places where a large part of the population is not from Spain, the test can be conducted in your native language.
There are many driving schools advertised in foreign language newspapers and magazines offering preparation for the Spanish test. If it is not available in your native tongue, you will have to take it in Spanish, and this can be challenging even for native speakers. The testing process is difficult and not cheap, the theory quite involved. You have three attempts to pass (this includes both the written and actual driving test) and then you have to pay additional fees for another three opportunities. The theory test consists of 40 questions, of which you can fail only three. So make sure if you sign up, you are prepared to dedicate considerable time to study and practice.
This can be a frustrating experience for drivers who have already held a driving license in their own country and been driving for many years.