如何在通过MS DevOps运行管道时在自托管(Linux Ubuntu 18.04)代理上指定python版本

2024-10-02 02:36:48 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图通过MS DevOps使用yaml管道运行一个简单的bash脚本。我想使用Python版本3.8。当通过SSH连接到自托管代理时,我能够毫无问题地运行yaml文件中指定的脚本。但是,当我通过管道运行脚本时,它失败了,因为出于某种原因,python别名引用的是Python 2.7.17

我尝试在agentsvc用户的.bashrcbash.bashrc文件中设置以下别名:alias python='python3.8'

我意识到我可以在脚本中将python更改为python3.8,但是我不想这样做。有人知道为什么alias不能在管道环境中工作吗?我能做些什么来解决这个问题

以下是我正在尝试运行的yaml管道示例:

pool: myubuntuagent

trigger:
  - master

steps:
  - script: |
      # install pre-requisites
      whoami
      python -V
      python -m pip install -r requirements.txt
    workingDirectory: '$(System.DefaultWorkingDirectory)'
    displayName: 'Install Prerequisites etc. etc. etc.'

Tags: install文件版本脚本bashyaml代理管道
1条回答
网友
1楼 · 发布于 2024-10-02 02:36:48

作为一种解决方法,我们可以尝试在cmd下面使用Python3.x版本

python3 -V
python3 -m pip install -r requirements.txt

结果:

enter image description here

此外,我们还可以使用任务Use Python version来指定python版本。您可以参考此doc来配置自托管代理以使用此任务

结果:

enter image description here

相关问题 更多 >

    热门问题