Depending on enum34 from a library

Vasiliy Faronov vfaronov at gmail.com
Sun Jul 24 16:10:15 EDT 2016


Hi all,

I'm building a Python library where I want to use Python 3.4-style
enums. Because I need to support Python 2.7, I'm considering using
enum34 [1]. But I'm not sure how to do this:

If I simply depend on enum34, it will install a module named `enum`
even in Python 3.4+ environments, and that could shadow the stdlib
module. Personally I would be very surprised if installing a library
caused an unrelated stdlib module to be replaced with a third-party
one, even if it's "just" a backport. However, in my environments,
`sys.path` is such that stdlib comes before site-packages -- perhaps
this is normal enough that I can rely on it?

Or I could change my setup.py to include enum34 in `install_requires`
only if running on Python 2.7. But that will make my distribution's
metadata dynamic, which doesn't sound like a good idea [2]. At the
very least, I think it will prevent me from building a universal
wheel.

So, what's the best current practice here?

[1] https://pypi.python.org/pypi/enum34
[2] https://mail.python.org/pipermail/distutils-sig/2009-July/012826.html


-- 
Vasiliy



More information about the Python-list mailing list