Home > OS >  gradle interactions with conda and pyenv
gradle interactions with conda and pyenv

Time:10-22

I have a simple gradle task which shells out to python to do some deployment stuff. However, it seems to use an arbitrary version of python in its commandLine call.

task deploy(type: Exec) {
    dependsOn 'clean'
    dependsOn 'build'
    tasks.findByName('build').mustRunAfter 'clean'
    workingDir "$buildDir/deploy/"
    commandLine "which", "python3"
}

yields /Users/cchow/projects/<project>/venv/bin/python3 as expected. I have a virtualenv active when I run the gradle command.

However, the below yields something unexpected

task deploy(type: Exec) {
    dependsOn 'clean'
    dependsOn 'build'
    tasks.findByName('build').mustRunAfter 'clean'
    workingDir "$buildDir/deploy/"
    commandLine "python3", "-m", "yaml"
}

yields /usr/local/Caskroom/miniconda/base/bin/python3: No module named yaml. I do have conda installed, but conda installs should have lower priority than virtualenvs. According to env when executed via commandLine "env":

PATH=/Users/cchow/projects/<project>/venv/bin:/usr/local/Caskroom/miniconda/base/condabin:<rest of path>

Why would it pick the virtualenv py3 for the former but the conda py3 for the latter block?

CodePudding user response:

I've encountered this problem too and have found this as a workaround:

project.exec  {
    commandLine "sh", "-c", "python -m foo"
}
  • Related