Nike-Inc / gimme-aws-creds

A CLI that utilizes Okta IdP via SAML to acquire temporary AWS credentials
Apache License 2.0
921 stars 262 forks source link

gimme-aws-creds.cmd can't find Python when it's not named `python3` #257

Open nl-brett-stime opened 3 years ago

nl-brett-stime commented 3 years ago

If the Python 3 executable on Windows is named python.exe instead of python3.exe, the .cmd file can't find it.

Expected Behavior

Running gimme-aws-creds.cmd from Windows with Python 3 should work.

Current Behavior

If the executable is named python.exe instead of python3.exe, then gimme-aws-creds.cmd won't work.

Possible Solution

PR coming...

MarkEvansHW commented 3 years ago

I'm having a problem I wonder if it is connected to this issue. When I run gimme-aws-creds at command line on my Windows laptop, I get the message "'"C:\Program"' is not recognized as an internal or external command, operable program or batch file.".

I checked and my Python is "python.exe", not "python3.exe" so wondering if connected this issue. Any thoughts or suggestions appreciated.

drwelby commented 3 years ago

If you have Execution Aliases for Python 3 turned on then this fix will find the Aliases first and you'll get the error message:

Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases.

even if you have Python 3 installed via other methods, such as Anaconda.

So if you get that error message but python3 works to start Python, go to Settings > App Execution Aliases, and turn off any you see for Python.

Screen Shot 2021-04-22 at 2 55 38 PM

I suspect that the fix that is finding python3 in the expression "%%~$PATH:j" is also the cause of @MarkEvansHW 's problem, finding Program Files instead of appdata directory and then not escaping the space.

edit:

%~$P:i - searches the directories listed in the P environment variable
         and expands %i to the fully qualified name of the first one found.
pelos commented 3 years ago

thanks @drwelby drwelby the part of Settings > App Execution Aliases did it for me =)

kkrav3ts commented 3 years ago

I'm having a problem I wonder if it is connected to this issue. When I run gimme-aws-creds at command line on my Windows laptop, I get the message "'"C:\Program"' is not recognized as an internal or external command, operable program or batch file.".

I checked and my Python is "python.exe", not "python3.exe" so wondering if connected this issue. Any thoughts or suggestions appreciated.

Hi @MarkEvansHW , did you manage to solve the issue with "'"C:\Program"' ? I am facing the same issue:

C:\Users\kyrylo.kravets>gimme-aws-creds --action-configure '"C:\KK\Apps\PyCharm"' is not recognized as an internal or external command, operable program or batch file.

Thanks!

kkrav3ts commented 3 years ago

I'm having a problem I wonder if it is connected to this issue. When I run gimme-aws-creds at command line on my Windows laptop, I get the message "'"C:\Program"' is not recognized as an internal or external command, operable program or batch file.". I checked and my Python is "python.exe", not "python3.exe" so wondering if connected this issue. Any thoughts or suggestions appreciated.

Hi @MarkEvansHW , did you manage to solve the issue with "'"C:\Program"' ? I am facing the same issue:

C:\Users\kyrylo.kravets>gimme-aws-creds --action-configure '"C:\KK\Apps\PyCharm"' is not recognized as an internal or external command, operable program or batch file.

Thanks!

In order to solve it, I removed this part of code from file gimme-aws-creds.cmd :

for /f "tokens=2 delims==" %%i in ('assoc .py') do ( for /f "tokens=2 delims==" %%j in ('ftype %%i') do ( for /f "tokens=1" %%k in ("%%j") do ( call :SetPythonExe %%k ) ) )

I am using Windows 10 Pro.

drwelby commented 3 years ago

Some other solutions that can work if your desired Python runs:

Copy gimme-aws-creds/blob/master/bin/gimme-aws-creds to the desktop, rename to gimme-aws-creds.py, right-click and make sure "Open with" is set to your Python. User can then double-click it.

or

Make a file called gimme-aws-creds.bat with contents start cmd /k python -c "from gimme_aws_creds.main import GimmeAWSCreds; GimmeAWSCreds().run()"

or

In Powershell, run Function gimme_fn {python -c "from gimme_aws_creds.main import GimmeAWSCreds; GimmeAWSCreds().run()" }; Set-Alias -Name gimme-aws-creds -Value gimme_fn

drwelby commented 3 years ago

@kkrav3ts Your file association for .py. is set to Pycharm, if you don't need/want Pycharm to open when you double-click a file, you can change it by right-click and "Open with" or use fname and assoc.

kkrav3ts commented 3 years ago

@drwelby Thanks a lot for these remarks!