Powershell install.ps1 script will throw error if at least one python is available
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 669
- Forks
- 236
- Avg merge
- 1m
- Merged PRs (30d)
- 4
Description
I was wanting to be able to keep the CLI updated using the install.ps1 script but encountered this error:
PS C:\Users\USERNAME> .\install.ps1 -AcceptAllDefaults
VERBOSE: Python found in registry: HKCU:\Software\Python\PythonCore
VERBOSE: Python found in registry: HKLM:\Software\Python\PythonCore
C:\Users\USERNAME\install.ps1 : Error: Python executable referenced in registry does not exist. Uninstall
or repair your Python installation manually and then re-run this script.
At line:1 char:1
.\install.ps1 -AcceptAllDefaults
CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,install.ps1
I discovered that I have an unclean install of Python due to enterprise management software uninstalling the global python versions automatically on my machine. As a result, the registry settings for my local python worked but the global did not. I found the relevant code and tested the logic for checking python versions and found that if either the local python or global python are missing, the script will throw an error before testing each version specifically.
Reference line of code: https://github.com/oracle/oci-cli/blob/ff1aaf6222235e29977b71cd50ede37dd15aa967/scripts/install/install.ps1#L308-L327
I verified that if I change this code to test the minimum requirements first, I was then successful in upgrading my OCI CLI version:
# check if Python is installed, and is greater than MinValidPythonVersion
$PythonExecutable = $null
$CurrentUserPythonExecutable = FindLatestPythonExecutableInRegistry "HKCU"
$LocalMachinePythonExecutable = FindLatestPythonExecutableInRegistry "HKLM"
# if python is installed in the registry but the corresponding python.exe doesn't exist
# then the user will need to repair or uninstall python and re-run the script
$PythonInstallationCorruptErrorMessage = "Error: Python executable referenced in registry does not exist. Uninstall or repair your Python installation manually and then re-run this script."
$CurrentUserPythonInstallationExeMissing = $LocalMachinePythonExecutable -And (-Not (Test-Path $LocalMachinePythonExecutable))
$LocalMachinePythonInstallationExeMissing = $CurrentUserPythonExecutable -And (-Not (Test-Path $CurrentUserPythonExecutable))
If (VerifyPythonExecutableMeetsMinimumRequirements -PythonExecutable $LocalMachinePythonExecutable) {
$PythonExecutable = $LocalMachinePythonExecutable
}
ElseIf (VerifyPythonExecutableMeetsMinimumRequirements -PythonExecutable $CurrentUserPythonExecutable) {
$PythonExecutable = $CurrentUserPythonExecutable
}
ElseIf ($CurrentUserPythonInstallationExeMissing -Or $LocalMachinePythonInstallationExeMissing) {
Write-Error $PythonInstallationCorruptErrorMessage
}
This is not a completed solution but an example of how I overcame it to determine feasibility of a potential solution. The OCI cli used the local python version and then continued successfully. I think a completed solution would need to test additional cases such as if global is available, but local is not. Possibly other things I am not thinking of, but I wanted to get the issue created to get comments and at a later point, I may submit a PR for a fix.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in scripts/install/install.ps1 around lines 308-327 and reproduce the case where HKCU and HKLM contain Python registry entries but one executable is missing. Run install.ps1 -AcceptAllDefaults with valid and stale registry entries; done means a valid Python executable is selected when available, while the corrupt-install error remains for cases with no usable installation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- powershell, python
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 62/100