前言
有些时候,我可能误解windows了。大概是因为我的无知吧!
python
安装python
win+s 快捷搜索开打powershell 右击以管理员执行
# 开启powershell执行策略
set-executionpolicy remotesigned
# 安装choco
iwr https://chocolatey.org/install.ps1 -UseBasicParsing | iex
# 升级choco
choco upgrade chocolatey
# 安装python
choco install -y python3
# 关闭终端,刷新环境变量,查看版本
python -v
安装pip
python -m pip install --upgrade pip
pip install --upgrade pip
虚拟环境
mkdir myproject
cd myproject
python -m venv my_env
ls my_env
my_env\Scripts\activate
常用
choco install openssh git -y
nodejs
# 0.vars
$normal_node="node-v10.14.1-win-x64"
$normal_node_zip=$normal_node+".zip"
$latest_node="node-v11.4.0-win-x64"
$latest_node_zip=$latest_node+".zip"
$npm_verson="v6.2.0-next.1"
$normal_node_zip_url="https://nodejs.org/dist/v10.14.1/node-v10.14.1-win-x64.zip"
$latest_node_zip_url="https://nodejs.org/dist/v11.4.0/node-v11.4.0-win-x64.zip"
$npm_zip_url="https://github.com/npm/npm/archive/v6.2.0-next.1.zip"
$nodedir="c:\NODE"
if ( !(Test-Path $nodedir))
{
md $nodedir
}
# 1. create dir
$start = Get-Date
if ( !(Test-Path $nodedir\node))
{
md $nodedir\node
}
if ( !(Test-Path $nodedir\npm-global))
{
md $nodedir\npm-global
}
if ( !(Test-Path $nodedir\npm-cache))
{
md $nodedir\npm-cache
}
if ( !(Test-Path $nodedir\zipfile))
{
md $nodedir\zipfile
}
# 2. download and ext
if (!(Test-Path $nodedir\zipfile\$latest_node_zip))
{
$client = new-object System.Net.WebClient
Write-Host $latest_node_zip_url
$client.DownloadFile("$latest_node_zip_url", "$nodedir\zipfile\$latest_node_zip")
if ( !(Test-Path $nodedir\zipfile\$latest_node))
{
Expand-Archive -Path $nodedir\zipfile\$latest_node_zip -DestinationPath $nodedir\zipfile\
}
}
if (!(Test-Path $nodedir\zipfile\$normal_node_zip))
{
$client = new-object System.Net.WebClient
$client.DownloadFile("$normal_node_zip_url", "$nodedir\zipfile\$normal_node_zip")
if ( !(Test-Path $nodedir\zipfile\$normal_node))
{
Expand-Archive -Path $nodedir\zipfile\$normal_node_zip -DestinationPath $nodedir\zipfile\
}
}
if (!(Test-Path $nodedir\zipfile\$npm_verson.zip))
{
[Net.ServicePointManager]::SecurityProtocol = "Tls12, Tls11, Tls, Ssl3"
Invoke-WebRequest -Uri $npm_zip_url -OutFile "$nodedir\zipfile\$npm_verson.zip"
if ( !(Test-Path $nodedir\zipfile\$npm_verson))
{
Expand-Archive -Path $nodedir\zipfile\$npm_verson.zip -DestinationPath $nodedir\zipfile\
}
}
$end = Get-Date
Write-Host -ForegroundColor Red ('download and Decompression node.js : ' + ($end - $start).TotalSeconds)
# 3.config nodejs
Copy-Item $nodedir\zipfile\$normal_node\node.exe $nodedir\node\$normal_node.exe
Copy-Item $nodedir\zipfile\$latest_node\node.exe $nodedir\node\$latest_node.exe
if (Test-Path $nodedir\node\node.exe)
{
Move-Item $nodedir\node\node.exe $nodedir\node\"node$(Get-Date -Format 'yyyyMdHms').exe"
}
Move-Item $nodedir\node\$latest_node.exe $nodedir\node\node.exe
# 4.edit path
$nodejspath="$nodedir\node"
$PathVariable= [System.Environment]::GetEnvironmentVariable("Path","Machine")
$PathFolders=$PathVariable.Split(";")
if ($PathFolders.Contains($nodejspath))
{
Write-Host "$nodejspath already exists"
}
else
{
if ($PathVariable.Trim().EndsWith(";"))
{
$PathVariable = $PathVariable + $nodejspath
}
else
{
$PathVariable = $PathVariable +";"+ $nodejspath
}
[System.Environment]::SetEnvironmentVariable("Path",$PathVariable,"Machine")
Write-Host "$nodejspath add to Path successfull"
}
$npmpath="$nodedir\NODE\npm-global"
$PathVariable= [System.Environment]::GetEnvironmentVariable("Path","Machine")
$PathFolders=$PathVariable.Split(";")
if ($PathFolders.Contains($npmpath))
{
Write-Host "$npmpath already exists"
}
else
{
if ($PathVariable.Trim().EndsWith(";"))
{
$PathVariable = $PathVariable + $npmpath
}
else
{
$PathVariable = $PathVariable +";"+ $npmpath
}
[System.Environment]::SetEnvironmentVariable("Path",$PathVariable,"Machine")
Write-Host "$npmpath add to Path successfull"
}
参考文章:https://blog.youkuaiyun.com/nakiri_arisu/article/details/82425402