Skip to content

Instantly share code, notes, and snippets.

@bohanyang
Last active May 13, 2024 04:48
Show Gist options
  • Save bohanyang/182adf58b91e0fdce3360b5ced893045 to your computer and use it in GitHub Desktop.
Save bohanyang/182adf58b91e0fdce3360b5ced893045 to your computer and use it in GitHub Desktop.
param (
[Parameter(Mandatory=$true)][string]$zip,
[string]$dir = "$HOME\Python"
)
if (Test-Path $dir) {
Remove-Item $dir
}
New-Item -Path $dir -ItemType Directory -Force
$7z = "$Env:Programfiles\7-Zip\7z.exe"
if (Test-Path $7z) {
Start-Process -NoNewWindow -Wait -PassThru -FilePath $7z -ArgumentList x,$zip,"-o$dir"
} else {
Expand-Archive -Path $zip -DestinationPath $dir -Force
}
New-Item -Path $dir -ItemType Directory -Force -Name Lib
New-Item -Path $dir -ItemType Directory -Force -Name DLLs
New-Item -Path $dir -ItemType Directory -Force -Name Scripts
$zip = Get-ChildItem -File -Path $dir\*.zip
if (Test-Path $7z) {
Start-Process -NoNewWindow -Wait -PassThru -FilePath $7z -ArgumentList x,$zip,"-o$dir\Lib"
} else {
Expand-Archive -Path $zip -DestinationPath $dir\Lib -Force
}
Get-ChildItem -File -Path $dir\*.dll,$dir\*.pyd,$dir\*.cat -Exclude vcruntime*.dll,python*.dll | Move-Item -Destination $dir\DLLs
Get-ChildItem -File -Path $dir\*._pth,$dir\*.zip | Remove-Item

Windows 绿色便携版 Python 环境

  1. 官网选择版本后,下载 embeddable zip file
  2. 打开 PowerShell,下载并执行脚本 .\install-python.ps1 python-3.9.0-embed-amd64.zip C:\Users\User\Python
  3. 如无权限则需设置 Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
  4. 在环境变量PATH中添加 C:\Users\User\PythonC:\Users\User\Python\Scripts
  5. 下载 https://bootstrap.pypa.io/get-pip.py 并执行 python get-pip.py 安装 pip
  6. pip install virtualenv 安装 virtualenv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment