Skip to content

gcloud has stopped working after 7.3.0 update #18529

Closed

Description

@andreikondratev

Prerequisites

Steps to reproduce

I installed 7.3.0 with msi and after that kept getting the error like when executing gcloud commands

google-cloud-sdk\platform\bundledpython\python.exe: can't find '__main__' module in ''

Tried to reinstall gcloud (with and without bundled python) and powershell a few times without much luck.

Works fine after downgrade to PS 7.2.5

Expected behavior

PS C:\> gcloud -h
Usage: gcloud [optional flags] <group | command>
  group may be           access-approval | access-context-manager |
                         active-directory | ai | ai-platform | anthos |
                         api-gateway | apigee | app | artifacts | asset |
                         assured | auth | batch | beta | bigtable | billing |
                         bms | builds | certificate-manager | cloud-shell |
                         components | composer | compute | config | container |
                         data-catalog | database-migration | dataflow |
                         dataplex | dataproc | datastore | datastream | debug |
                         deploy | deployment-manager | dns | domains |
                         edge-cloud | emulators | endpoints |
                         essential-contacts | eventarc | filestore | firebase |
                         firestore | functions | game | healthcare | iam | iap |
                         identity | ids | iot | kms | logging | memcache |
                         metastore | ml | ml-engine | monitoring |
                         network-connectivity | network-management |
                         network-security | network-services | notebooks |
                         org-policies | organizations | policy-intelligence |
                         policy-troubleshoot | privateca | projects | pubsub |
                         recaptcha | recommender | redis | resource-manager |
                         resource-settings | run | scc | scheduler | secrets |
                         service-directory | services | source | spanner | sql |
                         storage | tasks | topic | transcoder | transfer |
                         workflows | workspace-add-ons
  command may be         cheat-sheet | docker | feedback | help | info | init |
                         survey | version

For detailed information on this command and its flags, run:
  gcloud --help

Actual behavior

PS C:\> gcloud -h
google-cloud-sdk\platform\bundledpython\python.exe: can't find '__main__' module in ''

Error details

No response

Environment data

Name                           Value
----                           -----
PSVersion                      7.3.0
PSEdition                      Core
GitCommitId                    7.3.0
OS                             Microsoft Windows 10.0.22621
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

No response

Activity

  1. arifinsiam commented on Nov 11, 2022

    @arifinsiam

    facing the same issue, have you found any solutions yet?

  2. cesarjosue-reyes commented on Nov 11, 2022

    @cesarjosue-reyes

    Same issue

  3. al-cheb commented on Nov 11, 2022

    @al-cheb
    Contributor

    facing the same issue, have you found any solutions yet?

    There is no any issue with PowerShell Desktop.

  4. al-cheb commented on Nov 12, 2022

    @al-cheb
    Contributor
  5. andykcfung commented on Nov 14, 2022

    @andykcfung

    Another workaround is to start "cmd" inside powershell, login and then exit the "cmd" shell.

  6. andykcfung commented on Nov 14, 2022

    @andykcfung

    facing the same issue, have you found any solutions yet?

    There is no any issue with PowerShell Desktop.

    FWIW, "PowerShell Desktop" is a very old version of PowerShell. Run the command "$PSVersionTable" on mine and it shows "PSVersion" to be 5.1.x

  7. SteveL-MSFT commented on Nov 14, 2022

    @SteveL-MSFT
    Member

    If someone can confirm that setting $PSNativeCommandArgumentPassing = "Legacy" works and gcloud works, we can add that to legacy list so that it defaults to previous behavior. Also, is the actual command gcloud.exe or gcloud.cmd? The latter should automatically use legacy passing.

  8. SerhiiRohoza commented on Nov 14, 2022

    @SerhiiRohoza

    If someone can confirm that setting $PSNativeCommandArgumentPassing = "Legacy" works and gcloud works, we can add that to legacy list so that it defaults to previous behavior. Also, is the actual command gcloud.exe or gcloud.cmd? The latter should automatically use legacy passing.

    Works for me.

  9. ghost added
    In-PRIndicates that a PR is out for the issue
    on Nov 14, 2022
  10. ghost removed
    In-PRIndicates that a PR is out for the issue
    on Nov 15, 2022
  11. ghost removed
    Needs-TriageThe issue is new and needs to be triaged by a work group.
    on Nov 15, 2022
  12. daxian-dbw commented on Nov 16, 2022

    @daxian-dbw
    Member

    Re-open this issue.

    Running gcloud is not running gcloud.exe, but resolved to the gcloud.ps1 file under the installation folder. The gcloud.ps1 file eventually calls python.exe with a generated argument array. For the gcloud -h, the generated argument array is essentially the following array:

    $arg_array = $('', '-S', 'C:\Users\username\AppData\Local\Google\Cloud SDK\google-cloud-sdk\lib\gcloud.py', '-h')
    

    The leading empty string is the problem that cause it fail in the new Standard/Windows mode. With legacy mode, the leading empty string is ignored when passing to python.exe, but with the new standard/windows mode, the empty string is passed in as well, which causes python.exe to fail.

    gcloud will be removed from the list by #18575.
    For now, setting $PSNativeCommandArgumentPassing = "Legacy" is the workaround to use gcloud in PS 7.3.0

  13. SteveL-MSFT commented on Nov 16, 2022

    @SteveL-MSFT
    Member
  14. ghost closed this as completedon Nov 17, 2022
  15. veleek commented on Nov 30, 2022

    @veleek

    For anybody who runs into this issue and is looking for a quick workaround. Open up gcloud.ps1 (you can get the path using Get-Command gcloud | Select-Object Source) and then replace Line 109:

    $run_args_array += $cloudsdk_python_args.split(' ')

    with

    $run_args_array += $cloudsdk_python_args.split(' ', [StringSplitOptions]::RemoveEmptyEntries)
  16. catosaurusrex2003 commented on Dec 25, 2022

    @catosaurusrex2003

    may not be related to the real problem of this error but i was getting the exact same error and
    my error got SOLVED
    the problem was that while installing gcloud CLI i installed it just for my user on C drive , whereas i was calling gcloud outside of the user path.
    then i opened powershell inside user and then gcloud started to work

  17. alteredego commented on Jan 18, 2023

    @alteredego
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Resolution-ExternalThe issue is caused by external component(s).

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions