简体   繁体   English

使用 Azure Pipelines 为 Raspberry Pi 构建 Python 包

[英]Building Python packages for a Raspberry Pi using Azure Pipelines

I have set up two pipelines for a Python package.我为 Python 包设置了两个管道。 One is for Windows, the other is for Linux.一种用于 Windows,另一种用于 Linux。 The one for Windows works as expected. Windows 的那个按预期工作。 However, if I copy the Linux executable to a Raspberry, it won't run.但是,如果我将 Linux 可执行文件复制到 Raspberry,它将无法运行。 If I double click it, nothing happens and if I execute it using a terminal, I get permission denied.如果我双击它,没有任何反应,如果我使用终端执行它,我的权限被拒绝。 If I build the Python package locally on my Raspberry, everything works as expected.如果我在 Raspberry 本地构建 Python 包,一切都会按预期进行。

So basically my question is, do I need to specifically target Linux ARM for my Python app to run on my Raspberry?所以基本上我的问题是,我的 Python 应用程序是否需要专门针对 Linux ARM 才能在我的 Raspberry 上运行? If so, how can I achieve this?如果是这样,我怎样才能做到这一点? When creating a Pipeline, I can only choose between x86 and x64 architecture:创建流水线时,我只能在 x86 和 x64 架构之间进行选择:

在此处输入图片说明

Repo can be found here .回购可以在这里找到。

This is the pipeline I use for building and publishing:这是我用于构建和发布的管道:

trigger:
- master

jobs:

- job: 'Raspberry'
  pool:
    name: arm32 # Already tried to use a self-hosted build agent, but didn't get it to work
  variables:
    python.version: '3.7'

  steps:
    - task: UsePythonVersion@0
      inputs:
        versionSpec: '$(python.version)'

    - script: |
        cd AzurePipelinesWithPython
        python -m pip install --upgrade pip
      displayName: 'Install dependencies'

    - script: pip install pyinstaller
      name: 'pyinstaller'

    - script: cd AzurePipelinesWithPython && pyinstaller --onefile --noconfirm --clean test.py
      name: 'build'

    - task: PublishBuildArtifacts@1
      inputs:
        pathtoPublish: './AzurePipelinesWithPython/dist/'
        artifactName: 'AzurePipelinesWithPython-raspi-$(python.version)'

Sorry for not being able to post a Azure DevOps repo, it belongs to our corporate subscription and isn't public.抱歉,无法发布 Azure DevOps 存储库,它属于我们的公司订阅,不公开。

So basically my question is, do I need to specifically target Linux ARM for my Python app to run on my Raspberry?所以基本上我的问题是,我的 Python 应用程序是否需要专门针对 Linux ARM 才能在我的 Raspberry 上运行?

No, you don't need to specify it to target ARM for your app.不,您不需要指定它来为您的应用程序定位 ARM。 Especially, I think it won't make big effects even if you remove that task.特别是,我认为即使您删除该任务也不会产生太大影响。 If you're using hosted agent , it contains different python versions by default.如果您使用的是托管代理,默认情况下它包含不同的 Python 版本。 And if you use self-hosted agent, you just need to make sure the suitable version is installed in local machine.如果您使用自托管代理,您只需要确保在本地机器上安装了合适的版本。

However, if I copy the Linux executable to a Raspberry, it won't run.但是,如果我将 Linux 可执行文件复制到 Raspberry,它将无法运行。 If I double click it, nothing happens and if I execute it using a terminal, I get permission denied.如果我双击它,没有任何反应,如果我使用终端执行它,我的权限被拒绝。

For the strange behavior you met, I guess it didn't result from Azure Devops side.对于您遇到的奇怪行为,我想这不是 Azure Devops 方面的结果。 I searched and found several similar issues like yours, see one , two , three , four .我搜索并发现了几个与您类似的问题,请参阅

So I would think that it's more like a common issue in Linux environment, try using terminal to execute that program after using chmod u+x file_name to give the file the permission to run.所以我认为这更像是Linux环境中的一个常见问题,在使用chmod u+x file_name赋予文件运行权限后尝试使用终端执行该程序。 Also, you can use file xx.exe to check if the exe is generated correctly for Linux if the issue persists.此外,如果问题仍然存在,您可以使用文件 xx.exe来检查是否为 Linux 正确生成了 exe。 Hope all above gives a correct direction to resolve your issue.希望以上所有内容都能为解决您的问题提供正确的方向。

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

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