Distribute/distutils specify Python version
Asked Answered
V

1

5

Kinda followup to this... :)

My project is Python 3-only and my question is basically how I tell distutils/distribute/whoever that this package is Python 3-only?

Venous answered 14/11, 2012 at 18:52 Comment(6)
Are you trying to make it so pip 2.x will not see your app, or will refuse to install it, or just so that running python2.7 setup.py install will give an error? For the latter, bereal's solution is perfect.Sarnoff
I don't really care as long as it's not getting installed some way or the other ;)Venous
Then I'd accept bereal's answer. If you later put the package on PyPI and decide you want to handle pip 2 differently, you can always ask for that info later; no need to learn all that now if you don't plan to use it.Sarnoff
Actually I plan to publish it on PyPI ...Venous
In that case, if you're using the python setup.py register mechanism, I think a setup_requires dependency on python>=3.0 is enough to make distribute/pip/easy_install refuse to install your package in 2.x, and get the information onto the web page (but also put it in the long_description in human-readable terms). But someone who does python2.7 setup.py install will see an ugly traceback from a VersionConflict, so you'll still want the explicit version check to provide a nice message. (This is all off the top of my head; please research before relying on details.)Sarnoff
Oh, and you also want to use Programming Language :: Python :: 3 instead of the default Programming Language :: Python classifier. Anyway, all this is really just to prevent easy_install, pip, or whatever future tool comes out of the distribute2 project from having to download your package before giving an error.Sarnoff
P
9

Not sure if there's some special setting, but this in the beginning of setup.py might help:

import sys
if sys.version_info.major < 3:
    print("I'm only for 3, please upgrade")
    sys.exit(1)
Purdah answered 14/11, 2012 at 18:59 Comment(2)
+1. The idiomatic way to check version is sys.version_info < (3,) (I believe that's primarily to make it easier to change to (3, 1) when you want to drop support for 3.0), but I don't think this is really confusing or less readable.Sarnoff
FWIW I think it's more idiomatic to write it as .major < 3, because that immediately assigns meaning to the number. This doesn't really matter in this instance, since it's pretty obvious anyway, though ;)Venous

© 2022 - 2024 — McMap. All rights reserved.