Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Different python package requirements for 32 and 64 bit

Problem

My code depends on two packages A and B.

Recently I found an issue with the packages compatibility: maintainers of package A stopped releasing whl packages for 32 bit Python, while maintainers of package B removed some functionality, which package A relies on. Since package A relies on some functionality in package B, the code fails in runtime. When using 64 bit Python the problem goes away - all packages are synced nicely.

Of course I can manually suppress the upper version for package B, but it does not make sense for 64 bit version. It is preferable to use the newest versions for 64 bit Python. Yet it is necessary to allow Python 32 bit run smoothly as well, with older package versions, which I can define myself.

Question

I wonder if there is an opportunity to specify different package requirements for different bit versions.

Currently in setup.py we have install_requires field, but this is generic and not bit-specific.

Extra info

Excerpt from setup.py:

install_requires=[
    'A',
    'B',
]

I install my package in a dev environment:

$ pip install -e .

Update

I probably should have mentioned explicitly that here I want to differentiate between different Python bit versions (32 bit vs 64 bit) rather than OS architecture.

The only solution I managed to come up with is this:

is_32_bit = sys.maxsize <= 2**32
if is_32_bit:
    install_requires = ['A<=1.0', 'B<=1.0']
else:
    install_requires = ['A']


setup(
    ...
    install_requires=install_requires,
)
like image 792
Maxim Ivanov Avatar asked Dec 13 '25 13:12

Maxim Ivanov


1 Answers

Update

This is unfortunately not a solution to this problem since one cannot cover the case of 32bit Python installed on a 64bit OS using environment markers. platform_machine only gives you the architecture on the OS level, not for Python installation itself.

Original answer

You should be able to achieve this using the platform_machine environment marker:

install_requires=[
    "A<1.0;platform_machine!='x86_64' and platform_machine!='amd64'",
    "A>=1.0;platform_machine=='x86_64' or platform_machine=='amd64'"
]

Now A>=1.0 will be installed on 64bit architecture (x86_64 targets Unix, amd64 targets Windows) and A<1.0 everywhere else. If you need fine-grained control over more architectures (e.g. separate arm from i686 etc), add more requirement strings.

Reference: PEP 508, Environment Markers.

like image 94
hoefling Avatar answered Dec 16 '25 18:12

hoefling



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!