Search code examples
python-3.xazure-devopsazure-pipelinesazure-pipelines-build-taskazure-pipelines-tasks

Azure pipeline cannot find installed python libraries


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.


Solution

  • 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.