简体   繁体   English

从groovy脚本运行gsutil:找不到Python可执行文件

[英]Running gsutil from a groovy script: Could not find Python executable

I have a groovy script that fetches data about all of my app sales with various companies and generates reports for me. 我有一个时髦的脚本,该脚本可获取有关与多家公司进行的所有应用销售的数据并为我生成报告。 This has been working well, but I've migrated to a new server and now I'm running into a problem. 这一直运行良好,但是我已迁移到新服务器,现在遇到了问题。

To download Android app sales from Google Play, you have to use the gsutil command to copy the sales data from Google Storage. 要从Google Play下载Android应用销售,您必须使用gsutil命令从Google存储空间复制销售数据。 So, in my groovy script I execute that command. 因此,在常规脚本中,我执行了该命令。 It works just fine on my old server and when I issue the same command in my shell on the new server it works. 它在我的旧服务器上正常工作,当我在新服务器上的shell中发出相同命令时,它可以工作。

It just doesn't work on the new server from within the groovy script. 它只是在groovy脚本中在新服务器上不起作用。 Here is the error I get: 这是我得到的错误:

$ ./fetch_googleplay_report.groovy 2017-01-29
Fetching 2017-01-29 for Android Google Play
Running command: /usr/bin/gsutil cp -r gs://pubsite_prod_rev_XXXXXXXXXXXXX/sales/salesreport_201701.zip .
gsutil command output: 
gsutil command error output: which: no python2 in ((null))
which: no python2.7 in ((null))
Traceback (most recent call last):
  File "/usr/lib64/google-cloud-sdk/bin/bootstrapping/gsutil.py", line 75, in <module>
    main()
  File "/usr/lib64/google-cloud-sdk/bin/bootstrapping/gsutil.py", line 59, in main
    'platform/gsutil', 'gsutil', *args)
  File "/usr/lib64/google-cloud-sdk/bin/bootstrapping/bootstrapping.py", line 45, in ExecutePythonTool
    execution_utils.ArgsForPythonTool(_FullPath(tool_dir, exec_name), *args))
  File "/usr/lib64/google-cloud-sdk/lib/googlecloudsdk/core/execution_utils.py", line 170, in ArgsForPythonTool
    python_executable = kwargs.get('python') or GetPythonExecutable()
  File "/usr/lib64/google-cloud-sdk/lib/googlecloudsdk/core/execution_utils.py", line 59, in GetPythonExecutable
    raise ValueError('Could not find Python executable.')
ValueError: Could not find Python executable.

$ which python
/usr/bin/python
$ which python2
/usr/bin/python2

Python is definitely installed and in my path, but when gsutil is running when called by my groovy script, it can't seem to find it. Python确实已安装并且在我的路径中,但是当groovy脚本调用gsutil运行时,似乎无法找到它。 I'm guessing from the stacktrace that when it says no python2 in ((null)) it means that it's path is null. 我从stacktrace猜测,当它说no python2 in ((null)) ,意味着它的路径为null。 I'm not sure though. 我不确定。

Here is the groovy code snippet that is executing the command: 这是执行命令的常规代码段:

def cmd = "/usr/bin/gsutil cp -r gs://pubsite_prod_rev_XXXXXXXXXXX/sales/$reportfilename .";

println("Running command: $cmd")

def out = new StringBuffer(), err = new StringBuffer()
def proc = cmd.execute([], incomingdir)
proc.consumeProcessOutput(out, err)
proc.waitForOrKill(5000)

println("gsutil command output: $out")
println("gsutil command error output: $err")

EDIT: If I move the gsutil command into a shell script wherein I specifically source my .bash_profile to set up my PATH and have the groovy script call that shell script instead, then the file gets downloaded just fine. 编辑:如果我将gsutil命令移到一个shell脚本中,我专门从其中获取.bash_profile来设置我的PATH并让groovy脚本调用该shell脚本,那么下载文件就很好了。

So, this does appear to be a problem with gsutil getting called from a groovy script. 因此,这似乎是从groovy脚本调用gsutil的问题。 Any ideas? 有任何想法吗?

In this case you should prefix the execution of your Google Cloud SDK tools with CLOUDSDK_PYTHON=/usr/bin/python , eg. 在这种情况下,您应该在执行Google Cloud SDK工具的CLOUDSDK_PYTHON=/usr/bin/python加上CLOUDSDK_PYTHON=/usr/bin/python ,例如。

CLOUDSDK_PYTHON=/usr/bin/python gsutil cp -r ...

This workaround is from hidekuro in github.com/GoogleCloudPlatform/gsutil/issues/402 . 此解决方法来自github.com/GoogleCloudPlatform/gsutil/issues/402中的hidekuro

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM