创建一个ps1文件设置删除python环境变量
时间: 2024-09-13 19:04:08 浏览: 149
创建一个名为.ps1的Windows PowerShell脚本,用于设置并删除Python环境变量,可以按照以下步骤操作:
```powershell
# 定义函数:Set-EnvVariable
function Set-EnvVariable($name, $value) {
$env:$name = $value
Write-Host "Environment variable '$name' set to '$value'."
}
# 定义函数:Remove-EnvVariable
function Remove-EnvVariable($name) {
if ($env:$name) {
$env:$name = ""
Write-Host "Environment variable '$name' removed."
} else {
Write-Host "Environment variable '$name' not found."
}
}
# 示例:设置Python路径
$pythonPath = "C:\Python39\"
Set-EnvVariable "PYTHONPATH" $pythonPath
# 示例:删除Python路径
Remove-EnvVariable "PYTHONPATH"
# 使用说明
# 若要设置Python路径,只需运行 Set-EnvVariable 'PYTHONPATH' 'C:\Python39\' 即可。
# 若要删除Python路径,运行 Remove-EnvVariable 'PYTHONPATH'。
阅读全文