Should python imports last so long?

For the next team

%time python test.py 

on this script, test.py

 import numpy as np from math import * import matplotlib.pyplot as plt import matplotlib.cm as cm from matplotlib.colors import LogNorm from scipy import stats 

I get the output:

 real 0m1.933s user 0m1.322s sys 0m0.282s 

Is there something wrong? Or is it a long import?

+4
source share
1 answer

Some modules initialize when they are used, while others initialize everything as soon as you start it. Matplotlib is one of these modules.

Since matplotlib is a huge package that includes many features, I am not surprised that it takes a lot of time, although it can be annoying.

So, answering your question, yes, to some.

If you want to "solve" your problem, you can import matplotlib only when you are going to use it, or have a load / print screen at the beginning of your program.

+8
source

All Articles