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?
python3-pytz ) package will be deprecated in Fedora 35. Packages in Fedora should use Python standard library modules, such as dateutil.tz and zoneinfo (available since Python 3.9) instead.
localize() is the correct function to use for creating datetime aware objects with an initial fixed datetime value. The resulting datetime aware object will have the original datetime value.
virtualenv is a tool for creating isolated Python environments containing their own copy of python , pip , and their own place to keep libraries installed from PyPI. It's designed to allow you to work on multiple projects with different dependencies at the same time on the same machine.
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
It seems like in Windows just delete pytz-2013.9-py2.7.egg
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With