3

When I install pytz via setuptools, iterating over pytz.all_timezones takes multiple seconds. Someone suggested running pip unzip pytz, and that fixes the performance problem. Now I want to make setuptools install pytz uncompressed any time someone installs my package.

Can I configure setuptools to always unzip a particular dependency of my package?

$ virtualenv ve2.7
$ source ve2.7/bin/activate
(ve2.7)$ python setup.py install
(ve2.7)$ python slowpytz.py
2.62620520592s
(ve2.7)$ pip unzip pytz
DEPRECATION: 'pip zip' and 'pip unzip` are deprecated, and will be removed in a future release.
Unzipping pytz (in ./ve2.7/lib/python2.7/site-packages/pytz-2014.7-py2.7.egg)
(ve2.7)$ python slowpytz.py
0.0149159431458s

setup.py

from setuptools import setup
setup(name='slowpytz', version='0.0.1', install_requires=['pytz==2014.7'])

slowpytz.py

import pytz
import time
start = time.time()
zones = list(pytz.all_timezones)
print(str(time.time() - start) + 's')
Community
  • 1
  • 1
Dan Weaver
  • 1,081
  • 11
  • 17

1 Answers1

3

There's no way that I know of to force unzipping of your dependencies in all cases. Some things that fall slightly short of that, but might still be useful:

  • You could submit a bug report for pytz to set zip_safe=False in its setup.py, using performance data as a justification for the change.
  • Failing that, you could fork pytz, add zip_safe=False, and have your package depend on your fork. (Not a great option.)
  • You could recommend that users always install your package with pip, which always installs everything unzipped (including dependencies), rather than easy_install or python setup.py install.
  • If your users must use easy_install, you can recommend they use easy_install -Z, which forces unzipped installation.
Carl Meyer
  • 122,012
  • 20
  • 106
  • 116
  • Thanks for the ideas. My users are already installing with pip, but my tests use setup.py to install into virtual environments to test against various Python versions, which is where I found this issue. – Dan Weaver Sep 13 '14 at 00:27
  • 1
    @DanWeaver Why not use pip to install into virtual environments in your tests? Virtual environments always have pip installed in them, so it's definitely available, and it's scriptable. Or even better, why not use tox, which is a tool specifically designed to handle installing into virtualenvs to test against various Python versions (and uses pip to install)? – Carl Meyer Sep 13 '14 at 03:42
  • I didn't know I could do `pip install .`, but now I'm doing that instead of `python setup.py install` and `pip unzip pytz` for my tests. – Dan Weaver Sep 13 '14 at 14:27
  • 1
    @DanWeaver: you could use `tox` to run the tests on several python versions inside virtualenvs. `pip install -e .` installs without copying the source for development. – jfs Sep 14 '14 at 16:18
  • FWIW, I'm using tox now too. It's great. – Dan Weaver Dec 31 '14 at 06:57