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?

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. Commented Nov 14, 2012 at 19:03
  • I don't really care as long as it's not getting installed some way or the other ;) Commented Nov 14, 2012 at 19:04
  • 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. Commented Nov 14, 2012 at 19:08
  • Actually I plan to publish it on PyPI ... Commented Nov 14, 2012 at 19:09
  • 1
    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. Commented Nov 14, 2012 at 19:30

1 Answer 1

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)
Sign up to request clarification or add additional context in comments.

2 Comments

+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.
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 ;)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.