Google Cloud Install上的Python错误。如何正确设置环境变量?

时间:2016-11-21 20:11:37

标签: python python-2.7 google-app-engine

我正在尝试在 Windows 计算机上安装Google Cloud SDK。我目前在这台机器上安装了Python 2.7,它位于系统变量路径中,就像这样 - > C:\Python27\;

我在安装过程中收到此错误:

  

错误:gcloud无法加载:DLL加载失败:%1不是有效的Win32   应用

错误消息还提示我通过说:

来检查Python可执行文件
  

如果不是,请将CLOUDSDK_PYTHON环境变量设置为   指向一个可用的Python 2.7可执行文件。

所以,我正在尝试在install.sh shell脚本中设置CLOUDSDK_PYTHON环境变量......但是没有任何工作。以下是该文件的代码:

echo Welcome to the Google Cloud SDK!

if [ -z "$CLOUDSDK_PYTHON" ]; then
 if [ -z "$(which python)" ]; then
  echo
  echo "To use the Google Cloud SDK, you must have Python installed and on your PATH."
  echo "As an alternative, you may also set the CLOUDSDK_PYTHON environment variable"
  echo "to the location of your Python executable."
  exit 1
 fi
 CLOUDSDK_PYTHON="python"
fi

我已尝试 python2.7,以及可执行文件的路径C:\Python27,但是当我尝试使用这些变量运行脚本时,我收到此错误:

install.sh: line 128: $'python\r': command not found

我找到了这个stack question,但没有一个解决方案适合我。任何帮助将非常感谢。

5 个答案:

答案 0 :(得分:5)

sdk 指向 virtualenv python 时,我遇到了同样的问题。我在 Ubuntu

中使用默认的python2.7解决了这个问题

在termimal中输入

 mChart = (BarChart) compareDialog.findViewById(R.id.bar_chart);

 mChart.setDrawBarShadow(false);
 mChart.setDrawValueAboveBar(true);
 mChart.getDescription().setEnabled(false);
 mChart.setMaxVisibleValueCount(60);
 mChart.setPinchZoom(false);
 mChart.setDrawGridBackground(false);

 final Typeface tf = Typeface.createFromAsset(getAssets(),
                    "Arimo-Regular.ttf");

 XAxis xAxis = mChart.getXAxis();
 xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
 xAxis.setDrawGridLines(false);
 xAxis.setGranularity(1f);
 xAxis.setTypeface(tf);
 xAxis.setTextSize(16f);
 xAxis.setAxisMinimum(tests.size() - 8.5f);
 xAxis.setLabelCount(8);

 IAxisValueFormatter formatter = new IAxisValueFormatter() {
     @Override
     public String getFormattedValue(float value, AxisBase axis) {
         int intValue = (int) value;
          return (tests.size() > intValue && intValue >= 0) ? tests.get(intValue) : "";
     }
 };
 xAxis.setValueFormatter(formatter);

 YAxis yAxis = mChart.getAxisLeft();
 yAxis.setDrawGridLines(true);
 yAxis.setSpaceTop(15f);
 yAxis.setTypeface(tf);
 yAxis.setTextSize(16f);
 yAxis.setAxisMinimum(0f);
 yAxis.setLabelCount(10, false);

 YAxis rightAxis = mChart.getAxisRight();
 rightAxis.setEnabled(false);

 Legend l = mChart.getLegend();
 l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
 l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.LEFT);
 l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
 l.setDrawInside(false);
 l.setForm(Legend.LegendForm.SQUARE);
 l.setFormSize(9f);
 l.setTextSize(16f);
 l.setXEntrySpace(4f);

答案 1 :(得分:2)

这是因为gcloud.bat命令找不到合适的python.exe。我简单地把

解决了这个问题
SET CLOUDSDK_PYTHON=pathWherePythonexeLocate

进入google Cloud SDK文件夹中的文件cloud_env.bat。 并修改install.sh赢得的帮助,因为自env首次安装gcloud sdk时运行install.sh后,C:\myname\soft\python27.exe无效。 和sdk只支持python2.7,所以路径指向python2.7,例如var nums = [1.0000006, 0.00005, 2.54695621e-7];

答案 2 :(得分:2)

两种配置解决了我的问题。

  1. 我的笔记本电脑运行Windows 10,我发现有文件:
C:\Users\<myusername>\AppData\Local\Microsoft\WindowsApps\python.exe

该文件的大小为0 Kb。该目录位于实际安装Python的C:\ Python27路径之前。我尝试将C:\ Python27移到Path字符串中的较高位置,但这没有用。

虽然我没有重新引导,但确实打开了一个新的CMD窗口,并确认路径中的C:\ Python27高于AppData目录。仍然没有用。

  1. 当我更改CLOUDSDK_PYTHON路径时,仅“路径”是不够的。必须提供完整路径,其中包括可执行文件名称。

进行这两项更改可以使gCloud正常工作。

当然,当我完成上面的键入时,我看到了Google关于以下更改的电子邮件。

重要提示:Python 2.7在2020年1月1日之后将不再获得更新,因此gcloud自v274.0.0起将在Python 3x上运行。我找不到一个发布此信息的网页,但是此页面上提到更改:https://cloud.google.com/sdk/docs/quickstart-linux

答案 3 :(得分:1)

我解决这个问题的方法只是下载Versioned SDK而不是Interactive SDK。我手动将gcloud添加到我的路径中,一切正常。我仍然不知道为什么交互式下载不是从我的系统路径中找到Python,而是没有Python的Versioned SDK工作。

感谢@DanCornilescu提示。

答案 4 :(得分:1)

如果您在Windows上的274.0.0上遇到此问题,

在公共错误https://issuetracker.google.com/issues/146458519

中对此进行了跟踪

一个employee replied

  

我们为导致这些问题的两个文件提供了补丁。这些   适用于两种情况(在Windows上均适用):   1.新安装失败,或者   2.执行组件更新后,您将无法运行gcloud。

     

对于案例1,请下载附件文件install.bat,然后复制   它到您尝试安装gcloud的位置,例如   C:\ Program Files(x86)\ Google \ Cloud SDK \ google-cloud-sdk。然后跑   它,例如

> cd C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk
> .\install.bat
     

对于案例1和案例2,请下载附件gcloud.cmd,然后   将其复制到您的gcloud安装目录下的bin目录中,例如   C:\ Program Files(x86)\ Google \ Cloud SDK \ google-cloud-sdk \ bin。什么时候   提示您替换以前的副本,键入是。这应该允许   您可以运行gcloud而不提示您设置CLOUDSDK_PYTHON。

文件已附加在公共错误跟踪器中。