Azure管道找不到已安装的Python库。

huangapple go评论81阅读模式
英文:

Azure pipeline cannot find installed python libraries

问题

以下是我的构建YAML文件:
Azure管道找不到已安装的Python库。

我正在创建一个名为env的虚拟环境,并在其中安装pandas。构建成功发布了artifact。
当我下载了artifact并激活了env后,我遇到了导入错误,例如:
Azure管道找不到已安装的Python库。

我是否错误地假设artifact不按照我尝试的方式工作?
我是Azure DevOps管道的新手,需要严重的帮助来继续我的工作。

英文:

Below is my build yaml
Azure管道找不到已安装的Python库。

I am building a virtual environment named env and installing pandas into it. The artifact is published successfully.
When I downloaded the artifact and activated env, I get import errors. for e.g.
Azure管道找不到已安装的Python库。

Am I wrong in my assumption that artifacts don't work the way I am trying?
I am new to the Azure DevOps pipeline and need serious help to proceed with my work further.

答案1

得分: 0

我已成功将此工作导入并导入pandas。
我不得不在pip install中添加了相当多的额外参数才能使其工作。但是它已经可靠地工作了几年。这是部署到Linux部署(不确定是否重要)。

这是我的azure_pipelines.yml中的一部分:

    - task: UsePythonVersion@0
      displayName: '使用 Python 3.9'
      inputs:
        versionSpec: 3.9

    - bash: |
        python -m venv .venv
        source .venv/bin/activate
        pip install --upgrade pip
        pip install --target="./.python_packages/lib/site-packages" -r ./requirements.txt --use-pep517        
      workingDirectory: $(workingDirectory)
      displayName: '安装应用程序依赖项'

requirements.txt:

wheel
azure-functions
openpyxl
pandas

在pip install中使用额外的target参数的原因是因为其默认安装包的位置不是Azure期望找到它们的位置。因此,如果不在.python_packages/lib/site-packages中安装它们,构建将无法找到并导入它们。

英文:

I've got this working successfully and importing pandas.
I had to put quite a lot of extra parameters to pip install to get this to work. But it has been working reliably for a couple years now.
This is deploying to a Linux deployment (not sure if that matters or not).

Here is a snippet from my azure_pipelines.yml:

    - task: UsePythonVersion@0
      displayName: 'Use Python 3.9'
      inputs:
        versionSpec: 3.9

    - bash: |
        python -m venv .venv
        source .venv/bin/activate
        pip install --upgrade pip
        pip install --target="./.python_packages/lib/site-packages" -r ./requirements.txt --use-pep517
      workingDirectory: $(workingDirectory)
      displayName: 'Install application dependencies'

requirements.txt:

wheel
azure-functions
openpyxl
pandas

The reason for the extra target parameter in pip install, is because it's default location for installing packages is not where Azure is expecting to find them. So hence without installing them at .python_packages/lib/site-packages the build will not be able to find and import them.

huangapple
  • 本文由 发表于 2023年7月20日 10:31:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/76726316.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定