英文:
Azure pipeline cannot find installed python libraries
问题
以下是我的构建YAML文件:
我正在创建一个名为env的虚拟环境,并在其中安装pandas。构建成功发布了artifact。
当我下载了artifact并激活了env后,我遇到了导入错误,例如:
我是否错误地假设artifact不按照我尝试的方式工作?
我是Azure DevOps管道的新手,需要严重的帮助来继续我的工作。
英文:
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.
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论