0

Below is my build yaml enter image description here

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. enter image description here

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.

user3742631
  • 123
  • 1
  • 5

1 Answers1

0

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.

Dirk R
  • 602
  • 7
  • 14
  • I am downloading the artifact in my local machine and then activating the venv. I am unable to import any library which was installed during build stage. Also, I would like to know whether we can really work this way, I mean archive and build the artifact. then Download it and use like a normal project? – user3742631 Jul 20 '23 at 14:12
  • I don't see why that wouldn't work! Just that it is time consuming. What I did was to console into the Azure Function itself and play around with installing packages to see where Azure was expecting the files to be. – Dirk R Jul 20 '23 at 14:22
  • The problem is solved. Issue was the mismatch in vmimage and its version. – user3742631 Jul 21 '23 at 16:29
  • @user3742631 Since you haven't accepted my answer, will you be writing a new answer to help others who stumble on your question? Personally, I am unsure what you mean by mismatch with the vmimage version or how that fits into Azure Functions. – Dirk R Jul 24 '23 at 07:02
  • If you see my above question which has 2 screenshots. 1st one is the yml file where I've mentioned ubuntu-latest and in 2nd screenshot, you can see that I have downloaded artifact on macos. That's why python was not working and there were import errors. – user3742631 Jul 25 '23 at 10:49
  • Very interesting, thank you! Just throwing this out there. Perhaps a variable might help you? ${{ if eq(variables['Build.SourceBranchName'], 'main') }}: vmImageName: 'ubuntu-latest' ${{ if eq(variables['Build.SourceBranchName'], 'dev') }}: vmImageName: '??' vmImage: $(vmImageName) – Dirk R Jul 27 '23 at 09:03