0

UPDATE:

Now that I tried the solution from the answers to try

python -m ensurepip
python -m pip install --upgrade pip
pip install tox poetry

I realize that the self-hosted windows agent apparently did not even have the python. I followed this instruction from azure: use python version

where they say something like the direction structure.

$AGENT_TOOLSDIRECTORY/
Python/
    3.6.4/
        x64/
            {tool files}
        x64.complete

what is confusing is the definition of {tool files} Initially, I downloaded the python executable from the website enter image description here This gave me an .exe file. So I created a folder structure in c:/agent/_work/_tool/ as below

$AGENT_TOOLSDIRECTORY/
    Python/
        3.9.9/
            x64/
                python_3.9.9-amd64.exe
            x64.complete

Since this is definitely not the right way to do it. I am not sure what is the definition of {tool files}. I am currently stuck on how to correctly install python on the self-hosted windows agent.

Then I tried to use a venv to create folder architecture as advised in Link. Since the demo is for Linux, the venv installation turned out to be different. There was no bin folder created. And instead a pyvenv.cfg file was created. This venv configuration referred to path where the python was originally installed. The folder structure was as follows when I did this.

$AGENT_TOOLSDIRECTORY/
Python/
    3.6.4/
        x64/
            Include/
            Libs/
            Scripts/
            pyvenv.cfg
        x64.complete

This made the powershell task that was discussed below to fail as follows. From the cfg file the powershell tried to look for the python in users' folder istead of the _tool` folder.

enter image description here

I am lost here, any help is appreciated. Thanks a lot.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++

EARLIER ISSUE:

I am trying to create a Pipeline for my python project using self-hosted Windows agent. Here is the link to my repository where you can find the azure yml files. https://GringottsFinance@dev.azure.com/GringottsFinance/NLNETSalaryCalculator.Py/_git/NLNETSalaryCalculator.Py

For the tox related steps, I created this template

    parameters:
      PythonVersion: ''
      ToxEnvironment: ''
    
    steps:
      - checkout : self
        fetchDepth: 1
    
      - task: UsePythonVersion@0
        displayName: Use Python Version ${{ parameters.PythonVersion }}
        inputs:
          versionSpec: ${{ parameters.PythonVersion }}
        condition: succeeded()
    
      - powershell: pip install tox poetry
        displayName: Install Tox and Poetry
        condition: succeeded()
    
      - powershell: tox -r -e ${{ parameters.ToxEnvironment }}
        displayName: Run the give Tox Environment
        condition: succeeded()

My problem is that even though the python version 3.9.9 is successfully installed in the agent, the PowerShell doesn't seem to find the pip.

  • I have tried adding the path to environment variables.
  • I have also restarted the agent several times after adding the variables.

None of the solutions seem to work. Any help is appreciated.

Error Screen

2 Answers2

1

Azure self hosted windows agent's powershell can not find pip

I could reproduce this issue on my side.

You could resolve that issue with the following commands:

python -m ensurepip
python -m pip install --upgrade pip
pip install tox poetry

The test result:

enter image description here

Leo Liu
  • 71,098
  • 10
  • 114
  • 135
  • Hi Leo, I have updated the question. It turns out that even python was not installed properly as a tool in my self hosted windows machine. Do you have any idea about what this {tool files} mean? or can you help me properly setup the python for self hosted windows agent? – Ramanathan Varadharajan Jan 21 '22 at 19:50
  • @RamanathanVaradharajan, there is nothing in that filder, just a empty folder `x64`. – Leo Liu Jan 24 '22 at 08:53
  • @RamanathanVaradharajan, How about this issue noe? May I know the latest states of this ticket? – Leo Liu Jan 26 '22 at 07:42
  • I found the right way to install python. So the basic trick is to make the directory structure as said in the website. And install the python using windows installer in that x64 folder location. I will write a detailed answer when I get time. Thanks for you help! Highly appreciated. – Ramanathan Varadharajan Jan 28 '22 at 00:05
1

Okay, I figured out the solution on how to successfully install a windows self-hosted agent and configure python in it.

Here are the steps.

  1. Create a folder structure as follow inside the folder where the windows-agent-pool was configured.
$AGENT_TOOLSDIRECTORY/
Python/
    3.9.9/
        x64/
            {tool files}
        x64.complete

Now comes the tricky part

What do the {tool files} even mean. Here is what worked for me.

  1. I downloaded the windows installer for python from python-3.9.9-amd64.exe - Click to download
  2. Run the executable.
  3. Choose custom installation (Really important)
  4. Select all the checkboxes that appear.
  5. Select the above folder location as the directory where you wanted to install python. i.e. the directory we just created. So the installation location of python should be $AGENT_TOOLSDIRECTORY/Python/3.9.9/x64/

P.S. If you had followed the Microsoft instruction while installing the agent. your $AGENT_TOOLSDIRECTORY is just C:/agent/_work/_tool/. So the installation path for python should just be C:/agent/_work/_tool/Python/3.9.9/x64/

Ufff... that only took me three sleepless nights to figure out. Hope some of you can find a better use of the answer.

Thanks.