简体   繁体   English

为 arm64 架构编译 python 模块

[英]Compile python modules for arm64 architecture

I've been trying to install some python modules which use C code which is compiled based on the architecture of the host.我一直在尝试安装一些 python 模块,这些模块使用基于主机架构编译的C代码。 The final scripts would be deployed on an arm64 architecture, which does not have access to the internet, so installing the modules directly on it is impossible.最终的脚本将部署在无法访问互联网的 arm64 架构上,因此无法直接在其上安装模块。 My machine is an Intel Mac, so it has a different architecture than arm64.我的机器是 Intel Mac,所以它的架构与 arm64 不同。 I was thinking about creating a docker image with the arm64v8/python docker image and then transferring it into the arm64, but I get the error of:我正在考虑使用arm64v8/python docker 图像创建 docker 图像,然后将其传输到 arm64,但出现以下错误:

Using default tag: latest
latest: Pulling from arm64v8/python
no matching manifest for linux/amd64 in the manifest list entries

That means that this solution will not work.这意味着该解决方案将不起作用。

Does anyone have any tips or tricks on how to approach such problem?有人对如何解决此类问题有任何提示或技巧吗?

It's normal that you get this error.您收到此错误是正常的。 Your Mac is an x86_64 machine and the manifest for the arm64v8/python image does not contain your architecture, therefore you can't run it.您的 Mac 是x86_64机器, arm64v8/python映像的清单不包含您的架构,因此您无法运行它。

However, what you're trying to achieve is possible and you're in the right direction.但是,您尝试实现的目标是可能的,并且您的方向是正确的。 Your goal will be to build your code (and modules), targeting argm64v8 architecture and then build a docker image, with a different target architecture.您的目标是构建您的代码(和模块),以argm64v8架构为目标,然后构建具有不同目标架构的 docker 映像。 I think this here is a good starting point.我认为是一个很好的起点。

Solution to your problem is Cross-Compilation.您的问题的解决方案是交叉编译。 Cross-compilation means compile program on machine 2 (arch1) which will be run on machine 2 (arch2), where arch1.= arch2.交叉编译意味着在机器 2 (arch1) 上编译程序,该程序将在机器 2 (arch2) 上运行,其中 arch1.= arch2。 Good library for cross compilation is clang, Good example of cross compilation usage is android ecosystem, where you have code written in c/c++ and can be run on arm32, arm64.交叉编译的好库是 clang,交叉编译使用的好例子是 android 生态系统,你有用 c/c++ 编写的代码,可以在 arm32、arm64 上运行。 x86 or even x86_64. x86 甚至 x86_64。

Look here for examples: https://www.96boards.org/documentation/guides/crosscompile/commandline.html or https://github.com/tpoechtrager/osxcross在此处查看示例: https://www.96boards.org/documentation/guides/crosscompile/commandline.htmlZ5E056C500A1C4B6A7110B50D807BADE5xZ ://github.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM