Eclipse fever is building in Madrid, where residents and visitors are scrambling to get their hands on protective glasses ahead of a rare solar eclipse set to unfold near sunset on Wednesday.

At Madrid's Planetarium on Sunday, people lined up to buy eclipse glasses, with signs warning that free pairs had already sold out.

"We've come to the Planetarium to buy the glasses because most of them are sold out in the supermarkets and we were excited to see it," Madrid local resident Sofia Garcia de Vinuesa said. 

Australian visitor David Price made sure he was prepared, buying a spare pair after finding free glasses increasingly difficult to come by.

"All the free ones have disappeared in Madrid, which is quite shocking because it's a big city," Price said. 

A veteran eclipse watcher who has witnessed three before, Price said the timing of this week's event could make it particularly memorable.

For others, Wednesday will offer a long-awaited first glimpse of a solar eclipse.

Shanghai native Xiaoxi Wu said seeing one had been a dream, with the sunset setting adding to the anticipation.

"This year it will be solar eclipse during the sunset, so I guess it will be more romantic with all the sunset views," Wu said.

The August 12 eclipse will be the first total solar eclipse visible from the Iberian Peninsula since 1912, with the path of totality crossing parts of Spain as the sun approaches the horizon.

Totality will last less than two minutes in much of Spain before the moon continues across the sun and daylight returns, making the sunset timing and a clear western horizon key for viewers hoping to catch the spectacle.