Answer a question

I have installed pytz (v2013.8, but it happens in 2013.b, 2011k) in a virtualenv. The first call to

pytz.timezone("US/Eastern")

takes about 4 seconds. In a regular environment this is essentially instantaneous.

Does anyone have a trick to get this to run faster?

Answers

I actually came across the answer by playing around and looking at the source code. Since it gets its timezone settings from within the egg and the first call to timezone has to check that all the timezone files exist, the first call could be slow depending on how the os has to find those files. If pytz is installed using apt-get install python-tz then then call hits uncompressed files and is very fast. If it is installed using easy_install pytz then it hits one compressed file over and over again and is slower.

So the solution is to uncompress it. Luckily pip has a handy command.

tl;dr

pip unzip pytz
Logo

学AI,认准AI Studio!GPU算力,限时免费领,邀请好友解锁更多惊喜福利 >>>

更多推荐