Search code examples
pythonpipinstallationsetuptoolssetup.py

How to restrict python module to be installed in specific version of Python?


After wasting a couple of days with this, I'm asking for help. I'm trying to specify Python 2.7 in setup.py:

from setuptools import setup, find_packages

setup(
name = 'MyPackageName',
version = '1.0.0',
url = 'https://github.com/mypackage.git',
author = 'Author Name',
author_email = '[email protected]',
description = 'Description of my package',
packages = find_packages(),    
python_requires='>=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*',
)

My pip version is 9.0.1 (in Python 27)

My setuptools verion is 38.4.0 (in Python 27)

I have 3 Pythons installed: 2.5, 2.7, 3.6

I'm building an exe with (Python 27):

python setup.py bdist_wininst

which creates nice MyPackageName-1.0.0.win32.exe

This is what I'm trying to achieve(numpy example with Py 2.5): enter image description here

This is what I have: enter image description here

I would greatly appreciate any hints.


Solution

  • Use --target-version to restrict the interpreter version:

    $ python setup.py bdist_wininst --target-version 2.7
    

    will build the installer MyPackageName-1.0.0.win32-py2.7.exe. When installing, it will restrict the list of found versions to match the target one, or show an error dialog in there are none. Passing the option multiple times will generate multiple installers for each version, e.g.

    $ python setup.py bdist_wininst --target-version 2.5 --target-version 2.7
    

    will generate two installers, MyPackageName-1.0.0.win32-py2.5.exe and MyPackageName-1.0.0.win32-py2.7.exe.