First call to pytz.timezone is slow in virtualenv

一笑奈何 提交于 2019-12-22 04:26:11

问题


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?


回答1:


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



回答2:


It seems like in Windows just delete pytz-2013.9-py2.7.egg




回答3:


I had a hard time running

pip unzip pytz

as it says it cannot find the package. A workaround that I found which works was to edit the setup.py file and replacing

zip_safe=False

. (Set it to False). Then run the installer again:

python setup.py install

This solved my issue of slow loading time as well.



来源:https://stackoverflow.com/questions/20500910/first-call-to-pytz-timezone-is-slow-in-virtualenv

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!