4

I have a self-hosted agent that has Python3.8 installed on it. I can access the agent and run the pipeline for my python package. I get an error with the Agent.ToolsDirectory not matching the right version.

This is the log it outputs:

enter image description here

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Jeremy Miller
  • 45
  • 1
  • 1
  • 3

1 Answers1

3

Task Use Python version will not use the python installed in your local machine which hosts your agent. It will search the Python versions in Agent.ToolsDirectory. Python 3.8 is not included in Microsoft-hosted agents, and it is not included in Agent.ToolsDirectory.

In order to use the python version installed in your on-premise machine. You either need to point to the python.exe physical path in cmd task. Or add the python.exe path to environment variable path manually in powershell task. Please check below example.

To use local python in powershell task:

$env:Path += ";c:\{local path to}\Python\Python38\; c:\{local path to}\Python\Python38\Scripts\"
python -V

Or

c:\{local path to}\Python\Python38\python.exe -V
c:\{local path to}\Python\Python38\Scripts\pip.exe install

To use python in CMD task:

c:\{local path to}\Python\Python38\python.exe -V
c:\{local path to}\Python\Python38\Scripts\pip.exe install
Levi Lu-MSFT
  • 27,483
  • 2
  • 31
  • 43
  • I shoudl've mentioned this before but I already added Python to the environment variables. When I get the version from cmd or powershell, it return 'Python 3.8.0'. I named my environment variable 'Python', and when I "echo %Python%, it returns with 'C:\Python\Python38\python.exe'. I didn't do the 'pip.exe install' before so I did that and that did not fix my problem. – Jeremy Miller Jan 08 '20 at 14:34
  • 1
    @JeremeyMiller, It doesn't matter. The UsePython task searches for Python in the Agent.ToolDirectory. Read about it in the FAQ of this page https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/tool/use-python-version?view=azure-devops – YoavKlein Aug 04 '21 at 07:43