[英]Python Error on Google Cloud Install. How do I properly set the environment variable?
I am trying to install the Google Cloud SDK on my Windows machine.我正在尝试在我的Windows机器上安装 Google Cloud SDK。 I have Python 2.7 currently installed on this machine, and it's located in the System Variables Path like this ->
C:\\Python27\\;
我目前在这台机器上安装了 Python 2.7,它位于系统变量路径中,如下所示 ->
C:\\Python27\\;
I am getting this error during installation:我在安装过程中收到此错误:
ERROR: gcloud failed to load: DLL load failed: %1 is not a valid Win32 application.
错误:gcloud 加载失败:DLL 加载失败:%1 不是有效的 Win32 应用程序。
The error message also prompts me to check the Python executable by saying:该错误消息还提示我通过以下方式检查 Python 可执行文件:
If it is not, please set the CLOUDSDK_PYTHON environment variable to point to a working Python 2.7 executable.
如果不是,请将 CLOUDSDK_PYTHON 环境变量设置为指向可运行的 Python 2.7 可执行文件。
So, I'm trying to set the CLOUDSDK_PYTHON environment variable in the install.sh shell script...But nothing is working.所以,我试图在 install.sh shell 脚本中设置 CLOUDSDK_PYTHON 环境变量......但没有任何效果。 Here is the code from that file:
这是该文件中的代码:
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
I have tried python2.7
, and the path to the executable, C:\\Python27
, but I'm getting this error when I try to run the script with those variables:我尝试过
python2.7
和可执行文件的路径C:\\Python27
,但是当我尝试使用这些变量运行脚本时出现此错误:
install.sh: line 128: $'python\r': command not found
I found this stack question , but none of the solutions worked for me.我发现了这个堆栈问题,但没有一个解决方案对我有用。 Any help would be great appreciated.
任何帮助将不胜感激。
I had the same issue when the sdk was pointing to the virtualenv python .当sdk指向virtualenv python时,我遇到了同样的问题。 I solved it by using the default python2.7 in Ubuntu
我通过在Ubuntu 中使用默认的 python2.7 解决了它
Type this in termimal在终端输入这个
export CLOUDSDK_PYTHON=/usr/bin/python
The way I solved this was simply by downloading the Versioned SDK instead of the Interactive SDK.我解决这个问题的方法只是下载 Versioned SDK 而不是 Interactive SDK。 I manually added gcloud to my path, and all worked.
我手动将 gcloud 添加到我的路径中,并且一切正常。 I still don't know why the interactive download was not finding Python from my systems path, but the Versioned SDK without Python worked.
我仍然不知道为什么交互式下载没有从我的系统路径中找到 Python,但是没有 Python 的 Versioned SDK 可以工作。
Thanks for the tips @DanCornilescu.感谢@DanCornilescu 的提示。
Two configurations fixed my issue with this.两种配置解决了我的问题。
C:\Users\<myusername>\AppData\Local\Microsoft\WindowsApps\python.exe
That file is size 0 Kb.该文件的大小为 0 Kb。 This directory was ahead of the C:\\Python27 path where Python was actually installed.
该目录位于实际安装 Python 的 C:\\Python27 路径之前。 I tried moving C:\\Python27 higher in the Path string, but this did not work.
我尝试将 Path 字符串中的 C:\\Python27 移到更高的位置,但这不起作用。
While I did not reboot, I did open a fresh CMD window and confirmed that C:\\Python27 was higher in the path than the AppData directory.虽然我没有重新启动,但我确实打开了一个新的 CMD 窗口并确认路径中的 C:\\Python27 高于 AppData 目录。 Still did not work.
仍然没有工作。
Making these two changes enabled gCloud to work.进行这两项更改使 gCloud 能够正常工作。
Of course just as I finished typing the above, I saw email from Google regarding the change below.当然,就在我完成上面的输入时,我看到了来自谷歌的关于下面更改的电子邮件。
IMPORTANT NOTE Python 2.7 will no longer get updates after Jan 1, 2020, so gcloud as of v274.0.0 will run with Python 3x.重要说明Python 2.7 将在 2020 年 1 月 1 日之后不再获得更新,因此自 v274.0.0 起的 gcloud 将与 Python 3x 一起运行。 I can't find a web page announcing this, but there is mention of the change on this page: https://cloud.google.com/sdk/docs/quickstart-linux
我找不到宣布这一点的网页,但在此页面上提到了更改: https : //cloud.google.com/sdk/docs/quickstart-linux
This is because the gcloud.bat
command can't find the right python.exe.这是因为
gcloud.bat
命令找不到正确的 python.exe。 I solved the problem by simply put我简单地解决了这个问题
SET CLOUDSDK_PYTHON=pathWherePythonexeLocate
into the file cloud_env.bat
in google Cloud SDK file folder.进入 google Cloud SDK 文件夹中的文件
cloud_env.bat
。 And revise the install.sh
won't help, because it do nothing to the env
since the install.sh
was run when you first install gcloud sdk.和修订
install.sh
不会帮助,因为它什么都不做的env
因为install.sh
当你第一次安装gcloud SDK已运行。 and sdk only support python2.7, so the path is pointed to python2.7, such as C:\\myname\\soft\\python27.exe
而sdk只支持python2.7,所以路径指向python2.7,比如
C:\\myname\\soft\\python27.exe
if you are facing the issue on 274.0.0 on Windows,如果您在 Windows 上遇到 274.0.0 上的问题,
This is being tracked in the public bug https://issuetracker.google.com/issues/146458519这正在公共错误中跟踪https://issuetracker.google.com/issues/146458519
An employee replied :一位员工回复:
We have a patch for two files that are causing these problems.
我们为导致这些问题的两个文件提供了补丁。 These apply in two cases (both on Windows): 1. A new install fails, or 2. You are unable to run gcloud after performing a components update.
这些适用于两种情况(均在 Windows 上):1. 新安装失败,或 2. 在执行组件更新后无法运行 gcloud。
For case # 1, please download the attached file install.bat, and copy it to the location where you have attempted to install gcloud, eg C:\\Program Files (x86)\\Google\\Cloud SDK\\google-cloud-sdk.
对于第 1 种情况,请下载附件 install.bat,并将其复制到您尝试安装 gcloud 的位置,例如 C:\\Program Files (x86)\\Google\\Cloud SDK\\google-cloud-sdk。 Then run it, eg
然后运行它,例如
> cd C:\\Program Files (x86)\\Google\\Cloud SDK\\google-cloud-sdk > .\\install.bat
For both cases #1 and #2, download the attached file gcloud.cmd, and copy it to the bin directory under your gcloud installation, eg C:\\Program Files (x86)\\Google\\Cloud SDK\\google-cloud-sdk\\bin.
对于 #1 和 #2 两种情况,下载附件 gcloud.cmd,并将其复制到 gcloud 安装下的 bin 目录,例如 C:\\Program Files (x86)\\Google\\Cloud SDK\\google-cloud-sdk\\斌。 When prompted to replace the previous copy, type Yes.
当提示替换以前的副本时,键入 Yes。 This should allow you to run gcloud without being prompted to set CLOUDSDK_PYTHON.
这应该允许您在不提示设置 CLOUDSDK_PYTHON 的情况下运行 gcloud。
The files are attached in the public bug tracker.这些文件附加在公共错误跟踪器中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.