Skip to content

Update python3 to 3.13#1547

Open
emtuls wants to merge 4 commits intomainfrom
update-python
Open

Update python3 to 3.13#1547
emtuls wants to merge 4 commits intomainfrom
update-python

Conversation

@emtuls
Copy link
Member

@emtuls emtuls commented Dec 16, 2025

This aims to start pushing us towards a higher Python version, which is 3.13 for now as that seems to be a limit on some packages like pythonnet.

I attempted to split things that were Python 3.11 limited into their own packages and adjusted other ones up to 3.13 if they worked.

I made an additional shortcut for Python 3.13 in order to make it easier to access and for awareness that python 3.13 is the intended version to use (where all modules are installed to). The packages that use Python 3.11 have their own shortcuts that use Python 3.11, or are set to run as the author intended.

Ideally, I'd like to still aim towards managing multiple Python versions through pymanager as suggested in #1522 (comment), but I will dive down that path later. This was just a first stab at allowing us to move beyond Python 3.10.

There was an issue with pyreadline3 that required a small patch to mitigate a popup error when opening a Python 3.13 terminal, which is performed here: 496e289#diff-9ea4597286a609609159525cbb5b01aadcf7a99c030ab7bb07b657e5d322e6faR40-R65

I wanted to find ways to make Python 3.13 the default that opens when python is typed into a command prompt but most of the options didn't work well if I used cmd.exe. Ones that worked seemed possibly too destructive or didn't work well enough, but if someone has a suggestion, please let me know.
The main issue is that because of some tools now install python311 (like the 2 additional ones I created) and can be installed after python3.vm, that puts Python 3.11 at the top of the PATH, which is what Windows uses when trying to determine which python to use most of the time (particularly cmd.exe).

The one alternative I can think of at the moment would be to forgo having cmd.exe pick python 3.13 when typing python, and focus on Windows Terminal and/or Powershell to select it, which can likely be done via Profiles.

@emtuls emtuls self-assigned this Dec 16, 2025
@emtuls emtuls added 💎 enhancement It is working, but it could be better 🌀 FLARE-VM A package or feature to be used by FLARE-VM labels Dec 16, 2025
@emtuls emtuls force-pushed the update-python branch 2 times, most recently from 0ac0730 to eddbe48 Compare December 16, 2025 07:31
@emtuls emtuls force-pushed the update-python branch 3 times, most recently from 128e5b8 to b6b36bd Compare December 16, 2025 08:37
@emtuls emtuls requested a review from d35ha December 16, 2025 08:53
@emtuls
Copy link
Member Author

emtuls commented Dec 16, 2025

Open for comments and reviews @mandiant/flare-vm

@emtuls emtuls requested review from a team, VinceQu, binjo and mr-tz December 16, 2025 08:54
@emtuls emtuls added the ❔ discussion Further discussion is needed label Dec 16, 2025
@emtuls emtuls force-pushed the update-python branch 2 times, most recently from 5c17633 to 795daa3 Compare December 16, 2025 09:21
Copy link
Member

@d35ha d35ha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, consider pumping the version used at gostringungarbler.

$arguments = "-3.10 " + $filePath + " -h"

Comment on lines +4 to +12
$toolName = 'unpy2exe'
$category = VM-Get-Category($MyInvocation.MyCommand.Definition)

# Create output file to log python module installation details
$outputFile = VM-New-Install-Log ${Env:VM_COMMON_DIR}
Invoke-Expression "py -3.11 -W ignore -m pip install $toolName --disable-pip-version-check 2>&1 >> $outputFile"

$pyPath = (Get-Command py).Source
VM-Install-Shortcut -toolName $toolName -category $category -executablePath $pyPath -consoleApp $true -arguments "-3.11 -m unpy2exe"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unpy2exe is not installed as a library module (not executed with -m), it is installed as a separate script under the Scripts folder.

Suggested change
$toolName = 'unpy2exe'
$category = VM-Get-Category($MyInvocation.MyCommand.Definition)
# Create output file to log python module installation details
$outputFile = VM-New-Install-Log ${Env:VM_COMMON_DIR}
Invoke-Expression "py -3.11 -W ignore -m pip install $toolName --disable-pip-version-check 2>&1 >> $outputFile"
$pyPath = (Get-Command py).Source
VM-Install-Shortcut -toolName $toolName -category $category -executablePath $pyPath -consoleApp $true -arguments "-3.11 -m unpy2exe"
try {
$toolName = 'unpy2exe'
$category = VM-Get-Category($MyInvocation.MyCommand.Definition)
# Create output file to log python module installation details
$outputFile = VM-New-Install-Log ${Env:VM_COMMON_DIR}
Invoke-Expression "py -3.11 -W ignore -m pip install $toolName --disable-pip-version-check 2>&1 >> $outputFile"
$pyPath = (Get-Command py).Source
$toolPath = Join-Path (& $pyPath -3.11 -c "import site; print(site.getsitepackages()[0])") "Scripts\$toolName"
VM-Assert-Path $toolPath
VM-Install-Shortcut -toolName $toolName -category $category -executablePath $pyPath -consoleApp $true -arguments "-3.11 `"$toolPath`""
} catch {
VM-Write-Log-Exception $_
}

}

# Add Monkey Patch to `pyreadline3` for Python 3.13 compatibility
$sitePackages = python -c "import site; print(site.getsitepackages()[1])"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Specify the python version.

Suggested change
$sitePackages = python -c "import site; print(site.getsitepackages()[1])"
$sitePackages = py -3.13 -c "import site; print(site.getsitepackages()[1])"

} else {
# Fallback, just in case.
try {
$targetFile = & $(Get-Command python).Source -c "import sys; sys.path.append(r'C:\Python313\Lib\site-packages'); import readline; print(readline.__file__)"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Specify python version to be 3.13 for automatically importing the right readline module without hardcoding its directory.

Suggested change
$targetFile = & $(Get-Command python).Source -c "import sys; sys.path.append(r'C:\Python313\Lib\site-packages'); import readline; print(readline.__file__)"
$targetFile = py -3.13 -c "import readline; print(readline.__file__)"

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

Labels

🌀 FLARE-VM A package or feature to be used by FLARE-VM 💎 enhancement It is working, but it could be better ❔ discussion Further discussion is needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants