Efficient spectrogram generate

Hello,

I have been generating spectrograms using Python and libraries such as scipy, librosa and matplotlib, and it uses far too much resources (taking about a few minutes and GB of memory for hours long files) compared to audacity. I am pretty sure this cannot be explained only by the difference between Python and C++. I tried to dig into the code to see if there is a trick I can reproduce in a Python version but without success for now.
Is there anyone here who could point me into the right direction?

Thanks in advance.

It may be worth looking at how Friture generates spectrograms.