skip to Main Content

everyone!

First of all, thank you very much for taking the time to read this question. Without further delay, let me explain my situation.

I’m using Azure DevOps, specifically the Pipelines feature. I have a machine learning model, and I want to set up continuous integration and continuous deployment (CI/CD). My entire project is stored in the Azure Repos control code system.

I want to make sure I’m following best practices. I’ve already created and run my unit tests, and now I want to install the Python packages listed in my requirements.txt file.

Here are my questions and the issues I’m facing:

Question:

When I start the pipeline, and the agent begins its work, is it necessary to run requirements.txt? I mean, why is it needed? I’m not using that agent as a server or deployment source, so couldn’t I do this with a Docker image or another method?

Error:
When I run the job, I encounter an error that says it can’t find the requirements.txt file.

To give you an idea of my project structure, it looks like this:

myreponame/
    - folder1/
        - myfile.py
    - requirements/
        - requirements.txt

and my pipeline script looks like this:

# Check Branches
trigger:
  branches:
    include:
      - main

# Set VM Before Deploying
pool:
  vmImage: ubuntu-latest

# Starting Step
steps:
- script: |
    # Install Dependencies
    echo Checking and Installing Dependencies
    sudo apt-get update
    sudo apt-get install python3  # Install Python 3 (or python for Python 2)
- script: |
    echo Running Unit Tests
    python -m unittest discover -s test -p "*_test.py"
  displayName: 'Running Tests'
- script: |
    # Create a virtual environment
    # python -m venv myenv
    # source myenv/bin/activate
    python -m pip install --upgrade pip
    pip install -r requirements/requirements.txt
  displayName: 'Install Dependencies'

The error I’m encountering is:

ERROR: Could not open requirements file: [Errno 2] No such file or directory: 'requirements/requirements.txt'

I also tried:

pip install -r $(Build.SourcesDirectory)/requirements/requirements.txt

But that gave me:

ERROR: Could not open requirements file: [Errno 2] No such file or directory: '/home/vsts/work/1/s/requirements/requirements.txt'

I’m honestly not sure what I’m doing wrong because I’m new to DevOps, especially in the context of MLops.

Can someone please help me understand what’s going wrong and how to fix it? Thank you!

2

Answers


  1. Chosen as BEST ANSWER

    I followed

    GetShifting

    But i still get the same error.

    trigger:
     branches:
       include:
         - main
    
    # Set VM Before Deploying
    pool:
      vmImage: ubuntu-latest
    
    resources: 
     repositories:
       - repository: self
    
    # Starting Step
    steps:
    - checkout: self
    - script: |
        # Install Dependences
        echo Checking and Installing Dependences
        sudo apt-get update
        sudo apt-get install python3  # Install Python 3 (or python for Python 2)
    
    - script: |
        echo Running Unit Test
        python -m unittest discover -s test -p "*_test.py"
      displayName: 'Running Test'
    
    - script: |
        # Create a virtual environment
        python -m venv myenv
        source myenv/bin/activate
        python -m pip install --upgrade pip
        pip install -r requirements/requirements.txt
      displayName: 'Install Dependences'```
    
    Error :
    ERROR: Could not open requirements file: [Errno 2] No such file or directory: 'requirements/requirements.txt'
    

  2. You get the error because you’ve not checked out your repository.

    To the pipeline, before you start your steps add the repository as a resource:

    resources:
      repositories:
      - repository: self
    

    Then, in your steps make sure your first step is to use your repos:

      steps:
      - checkout: self
    

    If you still face issues you should add some logging showing your working path and list the directories. That will help you to figure out your exact path you need.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search