Python wheel packages Linux vs windows

眉间皱痕 提交于 2019-12-10 18:17:52

问题


Can one use the same python package (wheel file) for Linux , windows etc.? I am asking this as some packages include not only python files but EXEs as well, which I assume are python code turned into exe (at least with pip.exe and Django admin tool). Exe files are platform specific in the same way there are separate python interpreters for windows and Linux so that arises a question.


回答1:


Some wheel packages are cross-platform; some are platform-specific.

This information is included in the wheel's name. For example:

pytz-2018.4-py2.py3-none-any.whl (510kB)

That py2.py3 means that it works in any Python implementation, both Python 2.x and 3.x, and that non-any means that it works on any platform.

numpy-1.14.3-cp36-cp36m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl

That cp36-cp36m means that it works only in CPython 3.6, and that macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64 means that it's built for x86_64 macOS versions 10.9-10.10. (Roughly speaking, that's the minimum and recommended versions of macOS; most other platforms aren't quite as complicated.)


The most common reason for a package to be platform-specific is that it includes C API extension modules, as is the case with numpy. But there can be other reasons. For example, it may include a native executable to subprocess, or it may use ctypes to access system APIs, etc.




回答2:


A Python wheel is a packaging format, NOT an execution format. It's basically a .zip file.

Furthermore:

https://packaging.python.org/discussions/wheel-vs-egg/

...when the distribution only contains Python files (i.e. no compiled extensions), and is compatible with Python 2 and 3, it’s possible for a wheel to be “universal”, similar to an sdist.

From the same link:

A single wheel archive can indicate its compatibility with a number of Python language versions and implementations, ABIs, and system architectures.

In other words, the "wheel" format is designed to be as portable as possible ... and it also allows you to include platform-specific contents as required.



来源:https://stackoverflow.com/questions/50281252/python-wheel-packages-linux-vs-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!