Skip to content

Commit 6b6a583

Browse files
committed
Update Miniforge.ps1
1 parent cde0aee commit 6b6a583

File tree

3 files changed

+54
-115
lines changed

3 files changed

+54
-115
lines changed

Miniforge/Miniforge.ps1

Lines changed: 51 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ Param(
44
[String]$InstallationType = 'Computer',
55
[Switch]$InstallPwsh7SDK,
66
[Switch]$InstallDotnetInteractive,
7-
[Switch]$InstallNBExtensions,
8-
[Switch]$UsePipKernel,
97
[Switch]$CleanupDownloadFiles,
108
[String]$WorkingFolder = $PSScriptRoot
119
)
1210
$ErrorActionPreference = 'Stop'
1311
[Net.ServicePointManager]::SecurityProtocol = 'tls12, tls11, tls'
1412
Push-Location $WorkingFolder
13+
chcp 65001
14+
#$OutputEncoding = [System.Console]::OutputEncoding = [System.Console]::InputEncoding = [System.Text.Encoding]::GetEncoding('utf-8')
15+
$OutputEncoding = [System.Text.Encoding]::GetEncoding('utf-8')
1516
$psBoundParameters.Keys | ForEach-Object {
1617
if ($($PSBoundParameters.$_.GetType().Name) -eq 'SwitchParameter') {
1718
$paramStrings += " -$_"
@@ -20,27 +21,27 @@ $psBoundParameters.Keys | ForEach-Object {
2021
$paramStrings += " -$_ $($PSBoundParameters.$_)"
2122
}
2223
}
23-
Write-Verbose "Commandline: `"$PSCommandPath`"$paramStrings"
24+
Write-Host "Commandline: `"$PSCommandPath`"$paramStrings"
2425
switch ($installationType) {
2526
{ @('system', 'computer', 'allusers') -contains $_ } {
2627
if (-not([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
27-
Write-Verbose 'Relaunch script with admin privileges...'
28+
Write-Host 'Relaunch script with admin privileges...'
2829
Start-Process powershell.exe "-NoExit -ExecutionPolicy Bypass -Command `"$PSCommandPath`" $paramStrings" -Verb RunAs
2930
exit
3031
}
3132
$condaOpt = '/InstallationType=AllUsers /AddToPath=0 /RegisterPython=1 /NoRegistru=0 /Noscripts=o /S'
3233
$dataPath = "$env:ProgramData"
3334
$kernelPath = Join-Path $env:ProgramData '\miniforge3\share\jupyter\kernels'
3435
$packagePath = Join-Path $env:ProgramData '\miniforge3\Lib\site-packages'
35-
$pyTypeOpt = '--sys-prefix'
36+
#$pyTypeOpt = '--sys-prefix'
3637
[System.Environment]::SetEnvironmentVariable('PYTHONUTF8',1,[System.EnvironmentVariableTarget]::Machine)
3738
}
3839
{ @('user', 'justme') -contains $_ } {
3940
$condaOpt = '/InstallationType=JustMe /AddToPath=0 /RegisterPython=1 /NoRegistru=0 /Noscripts=o /S'
4041
$dataPath = $env:UserProfile
4142
$kernelPath = Join-Path $env:AppData '\jupyter\kernels'
4243
$packagePath = Join-Path $env:USERPROFILE '\miniforge3\Lib\site-packages'
43-
$pyTypeOpt = '--user'
44+
#$pyTypeOpt = '--user'
4445
[System.Environment]::SetEnvironmentVariable('PYTHONUTF8',1,[System.EnvironmentVariableTarget]::User)
4546
}
4647
default {
@@ -54,57 +55,44 @@ if ($ProgressPreference -ne 'SilentlyContinue') {
5455
$ProgressPreference = 'SilentlyContinue'
5556
}
5657

57-
Write-Verbose 'Downloading latest Miniforge...'
58+
Write-Host 'Downloading latest Miniforge...'
5859
$fileUri = 'https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Windows-x86_64.exe'
5960
Invoke-WebRequest -Uri $fileUri -UseBasicParsing -OutFile (Join-Path $WorkingFolder 'miniforge.exe') -Verbose
6061

61-
if ($InstallPwsh7ForPipKernel) {
62-
Write-Verbose 'Downloading latest PowerShell 7...'
63-
$releaseURI = 'https://github.com/PowerShell/PowerShell/releases'
64-
$latestRelease = (Invoke-WebRequest -Uri "$releaseURI/latest" -UseBasicParsing -Headers @{'Accept'='application/json'}| ConvertFrom-Json).update_url
65-
$versionString = $latestRelease -replace '.*tag/(.*)', '$1'
66-
$links = (Invoke-WebRequest -Uri "$releaseURI/expanded_assets/$($versionString)" -UseBasicParsing).Links.href
67-
$fileUri = 'https://github.com' + ($links | Select-String -Pattern '.*x64.msi' | Get-Unique).Tostring().Trim()
68-
Write-Verbose "Download from $fileUri"
69-
Invoke-WebRequest -Uri $fileUri -UseBasicParsing -OutFile (Join-Path $WorkingFolder 'pwsh.msi') -Verbose
70-
}
71-
7262
if ($InstallDotnetInteractive) {
73-
Write-Verbose 'Downloading latest .NET SDK...'
63+
Write-Host 'Downloading latest .NET SDK...'
7464
$links = (Invoke-WebRequest -Uri 'https://dotnet.microsoft.com/download' -UseBasicParsing).Links.href
7565
$latestVer = (($links | Select-String -Pattern '.*sdk.*windows-x64-installer') -replace '.*sdk-(([0-9]+\.){1}[0-9]+(\.[0-9]+)?)-.*', '$1' | Measure-Object -Maximum).Maximum
7666
$latestUri = 'https://dotnet.microsoft.com' + ($links | Select-String -Pattern ".*sdk-$latestVer-windows-x64-installer" | Get-Unique).Tostring().Trim()
7767
$fileUri = ((Invoke-WebRequest -Uri $latestUri -UseBasicParsing).Links.href | Select-String -Pattern '.*\.exe' | Get-Unique).Tostring().Trim()
7868
Invoke-WebRequest -Uri $fileUri -UseBasicParsing -OutFile (Join-Path $WorkingFolder 'dotnet.exe') -Verbose
7969
}
8070
else {
81-
Write-Verbose 'Downloading latest .NET Runtime...'
71+
Write-Host 'Downloading latest .NET Runtime...'
8272
$links = (Invoke-WebRequest -Uri 'https://dotnet.microsoft.com/en-us/download/dotnet/8.0/runtime' -UseBasicParsing).Links.href
8373
$latestVer = (($links | Select-String -Pattern '.*runtime.*windows-x64-installer') -replace '.*runtime-(([0-9]+\.){1}[0-9]+(\.[0-9]+)?)-.*', '$1' | Measure-Object -Maximum).Maximum
8474
$latestUri = 'https://dotnet.microsoft.com' + ($links | Select-String -Pattern ".*runtime-$latestVer-windows-x64-installer" | Get-Unique).Tostring().Trim()
8575
$fileUri = ((Invoke-WebRequest -Uri $latestUri -UseBasicParsing).Links.href | Select-String -Pattern '.*\.exe' | Get-Unique).Tostring().Trim()
8676
Invoke-WebRequest -Uri $fileUri -UseBasicParsing -OutFile (Join-Path $WorkingFolder 'dotnet.exe') -Verbose
8777
}
8878

89-
if (-not($UsePipKernel)) {
90-
$releaseURI = 'https://github.com/sakaztk/Jupyter-PowerShellSDK/releases'
91-
$latestRelease = (Invoke-WebRequest -Uri "$releaseURI/latest" -UseBasicParsing -Headers @{'Accept'='application/json'}| ConvertFrom-Json).update_url
92-
$versionString = $latestRelease -replace '.*tag/(.*)', '$1'
93-
$links = (Invoke-WebRequest -Uri "$releaseURI/expanded_assets/$($versionString)" -UseBasicParsing).Links.href
94-
Write-Verbose 'Downloading latest DeepAQ pwsh5 Kernel...'
95-
$fileUri = 'https://github.com' + ( $links | Select-String -Pattern '.*PowerShell5.zip' | Get-Unique).Tostring().Trim()
96-
Invoke-WebRequest -uri $fileUri -UseBasicParsing -OutFile (Join-Path $WorkingFolder 'PowerShell5.zip') -Verbose
97-
Write-Verbose 'Downloading latest DeepAQ pwshSDK Kernel...'
98-
$fileUri = 'https://github.com' + ( $links | Select-String -Pattern 'Jupyter-PowerShellSDK-7.*\.zip' | Get-Unique).Tostring().Trim()
99-
Invoke-WebRequest -uri $fileUri -UseBasicParsing -OutFile (Join-Path $WorkingFolder 'PowerShellSDK.zip') -Verbose
100-
}
79+
$releaseURI = 'https://github.com/sakaztk/Jupyter-PowerShellSDK/releases'
80+
$latestRelease = (Invoke-WebRequest -Uri "$releaseURI/latest" -UseBasicParsing -Headers @{'Accept'='application/json'}| ConvertFrom-Json).update_url
81+
$versionString = $latestRelease -replace '.*tag/(.*)', '$1'
82+
$links = (Invoke-WebRequest -Uri "$releaseURI/expanded_assets/$($versionString)" -UseBasicParsing).Links.href
83+
Write-Host 'Downloading latest DeepAQ pwsh5 Kernel...'
84+
$fileUri = 'https://github.com' + ( $links | Select-String -Pattern '.*PowerShell5.zip' | Get-Unique).Tostring().Trim()
85+
Invoke-WebRequest -uri $fileUri -UseBasicParsing -OutFile (Join-Path $WorkingFolder 'PowerShell5.zip') -Verbose
86+
Write-Host 'Downloading latest DeepAQ pwshSDK Kernel...'
87+
$fileUri = 'https://github.com' + ( $links | Select-String -Pattern 'Jupyter-PowerShellSDK-7.*\.zip' | Get-Unique).Tostring().Trim()
88+
Invoke-WebRequest -uri $fileUri -UseBasicParsing -OutFile (Join-Path $WorkingFolder 'PowerShellSDK.zip') -Verbose
10189

10290
if ($null -ne $exProgressPreference) {
10391
Write-Verbose "Restore $ProgressPreference to $exProgressPreference"
10492
$ProgressPreference = $exProgressPreference
10593
}
10694

107-
Write-Verbose 'Installing Miniforge...'
95+
Write-Host 'Installing Miniforge...'
10896
$process = Start-Process -FilePath 'miniforge.exe' -ArgumentList $condaOpt -PassThru
10997
for($i = 0; $i -le 100; $i = ($i + 1) % 100) {
11098
Write-Progress -Activity 'Installer' -PercentComplete $i -Status 'Installing...'
@@ -128,57 +116,33 @@ conda install -y notebook
128116
conda install -y jupyterlab
129117
conda install -y -c conda-forge nodejs
130118

131-
if ($InstallNBExtensions) {
132-
conda install -y -c conda-forge jupyter_nbextensions_configurator
133-
jupyter nbextensions_configurator enable
134-
pip install https://github.com/ipython-contrib/jupyter_contrib_nbextensions/tarball/master
135-
jupyter contrib nbextension install $pyTypeOpt
136-
}
137-
if ($UsePipKernel) {
138-
pip install powershell_kernel
139-
python -m powershell_kernel.install $pyTypeOpt
140-
if ($InstallPwsh7ForPipKernel) {
141-
Write-Verbose 'Installing PowerShell 7...'
142-
Start-Process -FilePath 'pwsh.msi' -ArgumentList '/passive' -Wait
143-
Copy-Item -Path "$kernelPath\powershell" -Destination "$kernelPath\powershell7" -Recurse -Force
144-
$fileContent = Get-Content "$kernelPath\powershell7\kernel.json" -Raw
145-
$fileContent = $filecontent -replace '"display_name": "[^"]*"','"display_name": "PowerShell 7"'
146-
$fileContent = $filecontent -replace '"powershell_command": "[^"]*"',"`"powershell_command`": `"pwsh.exe`""
147-
$filecontent | Set-Content "$kernelPath\powershell7\kernel.json"
148-
if ($CleanupDownloadFiles) {
149-
Start-Sleep -Seconds 5
150-
Remove-Item 'pwsh.msi' -Force
151-
}
152-
}
153-
}
154-
else {
155-
Write-Verbose 'Installing DeepAQ pwsh5 Kernel...'
156-
$installPath = Join-Path $packagePath 'powershell5_kernel'
157-
Expand-Archive -Path (Join-Path $WorkingFolder 'PowerShell5.zip') -DestinationPath $installPath -Force
158-
New-Item -ItemType Directory -Path (Join-Path $kernelPath '\powershell5\') -Force
159-
Invoke-WebRequest -UseBasicParsing -Verbose -Uri 'https://raw.githubusercontent.com/PowerShell/PowerShell/master/assets/Powershell_64.png' -OutFile (Join-Path $kernelPath '\powershell5\logo-64x64.png')
160-
Add-Type -AssemblyName System.Drawing
161-
$image = [System.Drawing.Image]::FromFile((Join-Path $kernelPath '\powershell5\logo-64x64.png'))
162-
$bitmap32 = New-Object System.Drawing.Bitmap(32, 32)
163-
[System.Drawing.Graphics]::FromImage($bitmap32).DrawImage($image, 0, 0, 32, 32)
164-
$bitmap32.Save((Join-Path $kernelPath '\powershell5\logo-32x32.png'), [System.Drawing.Imaging.ImageFormat]::Png)
119+
Write-Host 'Installing DeepAQ pwsh5 Kernel...'
120+
$installPath = Join-Path $packagePath 'powershell5_kernel'
121+
Expand-Archive -Path (Join-Path $WorkingFolder 'PowerShell5.zip') -DestinationPath $installPath -Force
122+
New-Item -ItemType Directory -Path (Join-Path $kernelPath '\powershell5\') -Force
123+
Invoke-WebRequest -UseBasicParsing -Verbose -Uri 'https://raw.githubusercontent.com/PowerShell/PowerShell/master/assets/Powershell_64.png' -OutFile (Join-Path $kernelPath '\powershell5\logo-64x64.png')
124+
Add-Type -AssemblyName System.Drawing
125+
$image = [System.Drawing.Image]::FromFile((Join-Path $kernelPath '\powershell5\logo-64x64.png'))
126+
$bitmap32 = New-Object System.Drawing.Bitmap(32, 32)
127+
[System.Drawing.Graphics]::FromImage($bitmap32).DrawImage($image, 0, 0, 32, 32)
128+
$bitmap32.Save((Join-Path $kernelPath '\powershell5\logo-32x32.png'), [System.Drawing.Imaging.ImageFormat]::Png)
165129
@"
166130
{
167-
"argv": [
168-
"$($installPath.replace('\','/'))/Jupyter_PowerShell5.exe",
169-
"{connection_file}"
170-
],
171-
"display_name": "PowerShell 5",
172-
"language": "Powershell"
131+
"argv": [
132+
"$($installPath.replace('\','/'))/Jupyter_PowerShell5.exe",
133+
"{connection_file}"
134+
],
135+
"display_name": "PowerShell 5",
136+
"language": "Powershell"
173137
}
174138
"@ | Set-Content -Path (Join-Path $kernelPath '\powershell5\kernel.json')
175-
Move-Item -Path (Join-Path $installPath '*.png') -Destination (Join-Path $kernelPath '\powershell5\') -Force
176-
if ($CleanupDownloadFiles) {
177-
Remove-Item (Join-Path $WorkingFolder 'PowerShell5.zip') -Force
178-
}
139+
Move-Item -Path (Join-Path $installPath '*.png') -Destination (Join-Path $kernelPath '\powershell5\') -Force
140+
if ($CleanupDownloadFiles) {
141+
Remove-Item (Join-Path $WorkingFolder 'PowerShell5.zip') -Force
179142
}
143+
180144
if ($InstallPwsh7SDK) {
181-
Write-Verbose 'Installing DeepAQ pwshSDK Kernel...'
145+
Write-Host 'Installing DeepAQ pwshSDK Kernel...'
182146
$installPath = Join-Path $packagePath 'powershellSDK_kernel'
183147
Expand-Archive -Path (Join-Path $WorkingFolder 'PowerShellSDK.zip') -DestinationPath $installPath -Force
184148
New-Item -ItemType Directory -Path (Join-Path $kernelPath '\powershellSDK\') -Force
@@ -190,12 +154,12 @@ if ($InstallPwsh7SDK) {
190154
$bitmap32.Save((Join-Path $kernelPath '\powershellSDK\logo-32x32.png'), [System.Drawing.Imaging.ImageFormat]::Png)
191155
@"
192156
{
193-
"argv": [
194-
"$($installPath.replace('\','/'))/Jupyter_PowerShellSDK.exe",
195-
"{connection_file}"
196-
],
197-
"display_name": "PowerShell 7 (SDK)",
198-
"language": "Powershell"
157+
"argv": [
158+
"$($installPath.replace('\','/'))/Jupyter_PowerShellSDK.exe",
159+
"{connection_file}"
160+
],
161+
"display_name": "PowerShell 7 (SDK)",
162+
"language": "Powershell"
199163
}
200164
"@ | Set-Content -Path (Join-Path $kernelPath '\powershellSDK\kernel.json')
201165
Move-Item -Path (Join-Path $installPath '*.png') -Destination (Join-Path $kernelPath '\powershellSDK\') -Force
@@ -205,9 +169,9 @@ if ($InstallPwsh7SDK) {
205169
}
206170

207171
if ($InstallDotnetInteractive) {
208-
Write-Verbose 'Installing .NET Core SDK...'
172+
Write-Host 'Installing .NET Core SDK...'
209173
Start-Process -FilePath 'dotnet.exe' -ArgumentList '/install /passive /norestart' -Wait
210-
Write-Verbose 'Installing .NET Interactive...'
174+
Write-Host 'Installing .NET Interactive...'
211175
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
212176
dotnet tool install -g --add-source "https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-tools/nuget/v3/index.json" Microsoft.dotnet-interactive
213177
dotnet interactive jupyter install --path "$kernelPath"
@@ -217,7 +181,7 @@ if ($InstallDotnetInteractive) {
217181
}
218182
}
219183
elseif ($InstallPwsh7SDK) {
220-
Write-Verbose 'Installing .NET Runtime...'
184+
Write-Host 'Installing .NET Runtime...'
221185
Start-Process -FilePath (Join-Path $WorkingFolder 'dotnet.exe') -ArgumentList '/install /passive /norestart' -Wait
222186
if ($CleanupDownloadFiles) {
223187
Start-Sleep -Seconds 5

Miniforge/README-JP.md

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,9 @@
33

44
## インストールするソフトウェア
55
- [Miniforge](https://github.com/conda-forge/miniforge)
6+
- [Node.js](https://nodejs.org/) (Use in extentions for JupyterLab)
67
- [Jupyter-PowerShell5](https://github.com/DeepAQ/Jupyter-PowerShell5)
78
- [Jupyter-PowerShellSDK](https://github.com/sakaztk/Jupyter-PowerShellSDK) (オプション)
8-
- [Jupyter Powershell Kernel](https://github.com/vors/jupyter-powershell) (オプション)
9-
- [Node.js](https://nodejs.org/) (Use in extentions for JupyterLab)
10-
- [PowerShell 7](https://github.com/PowerShell/PowerShell) (オプション)
11-
- [Jupyter Nbextensions](https://github.com/ipython-contrib/jupyter_contrib_nbextensions) (Optional)
12-
- [Jupyter Nbextensions Configurator](https://github.com/Jupyter-contrib/jupyter_nbextensions_configurator) (オプション)
139
- [.Net Interactive](https://github.com/dotnet/interactive) (オプション)
1410

1511
## インストール方法
@@ -22,19 +18,10 @@
2218
デフォルト: Computer
2319
例: .\Miniforge.ps1 -InstallationType User
2420

25-
- UsePipKernel
26-
このスイッチオプションを指定すると、[Jupyter-PowerShell5](https://github.com/DeepAQ/Jupyter-PowerShell5)の代わりに[Jupyter Powershell Kernel](https://github.com/vors/jupyter-powershell)を使用します。
27-
例: .\WinPython.ps1 -UsePipKernel
28-
2921
- InstallPwsh7SDK
3022
このスイッチオプションを指定すると、 [Jupyter-PowerShellSDK](https://github.com/sakaztk/Jupyter-PowerShellSDK)をインストールします。
3123
例: .\Anaconda.ps1 -InstallPwsh7SDK
3224

33-
- InstallNBExtensions
34-
このスイッチオプションを指定すると、 [Jupyter Nbextensions](https://github.com/ipython-contrib/jupyter_contrib_nbextensions)[Jupyter Nbextensions Configurator](https://github.com/Jupyter-contrib/jupyter_nbextensions_configurator)をインストールします。
35-
[Note] インストールすることでJupyterLabのエクスポート機能が使えなくなる可能性があります。([*](https://github.com/jupyterlab/jupyterlab-desktop/issues/465))
36-
例: .\Miniforge.ps1 -InstallNBExtensions
37-
3825
- InstallDotnetInteractive
3926
このスイッチオプションを指定すると、[.Net Interactive](https://github.com/dotnet/interactive)をインストールします。
4027
例: .\Miniforge.ps1 -InstallDotnetInteractive

Miniforge/README.md

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,25 @@ Using [Powershell](https://github.com/PowerShell/PowerShell) on [Jupyter Noteboo
33

44
## Installing Softwares
55
- [Miniforge](https://github.com/conda-forge/miniforge)
6+
- [Node.js](https://nodejs.org/) (Use in extentions for JupyterLab)
67
- [Jupyter-PowerShell5](https://github.com/DeepAQ/Jupyter-PowerShell5)
78
- [Jupyter-PowerShellSDK](https://github.com/sakaztk/Jupyter-PowerShellSDK) (Optional)
8-
- [Jupyter Powershell Kernel](https://github.com/vors/jupyter-powershell) (Optional)
9-
- [Node.js](https://nodejs.org/) (Use in extentions for JupyterLab)
10-
- [PowerShell 7](https://github.com/PowerShell/PowerShell) (Optional)
11-
- [Jupyter Nbextensions](https://github.com/ipython-contrib/jupyter_contrib_nbextensions) (Optional)
12-
- [Jupyter Nbextensions Configurator](https://github.com/Jupyter-contrib/jupyter_nbextensions_configurator) (Optional)
139
- [.Net Interactive](https://github.com/dotnet/interactive) (Optional)
1410

1511
## Installations
1612
.\Miniforge.ps1 [Script Option(s)]
13+
1714
## Script Options
1815
- InstallationType [Computer | User]
1916
Specify insatallation target to the Computer(All Users) or a User(Just Me).
2017
Mandatory: No
2118
Default: Computer
2219
e.g.: .\Miniforge.ps1 -InstallationType User
2320

24-
- UsePipKernel
25-
This switch option will install [Jupyter Powershell Kernel](https://github.com/vors/jupyter-powershell) instead of [Jupyter-PowerShell5](https://github.com/DeepAQ/Jupyter-PowerShell5).
26-
e.g.: .\WinPython.ps1 -UsePipKernel
27-
2821
- InstallPwsh7SDK
2922
This switch option will install [Jupyter-PowerShellSDK](https://github.com/sakaztk/Jupyter-PowerShellSDK).
3023
e.g.: .\Anaconda.ps1 -InstallPwsh7SDK
3124

32-
- InstallNBExtensions
33-
This switch option will install [Jupyter Nbextensions](https://github.com/ipython-contrib/jupyter_contrib_nbextensions) and [Jupyter Nbextensions Configurator](https://github.com/Jupyter-contrib/jupyter_nbextensions_configurator).
34-
[Note] It may not work export function for JupyterLab if install NBExtensions.([*](https://github.com/jupyterlab/jupyterlab-desktop/issues/465))
35-
e.g.: .\Miniforge.ps1 -InstallNBExtensions
36-
3725
- InstallDotnetInteractive
3826
This switch option will install latest powershell 7 and available it in Jupyter Notebook options.
3927
e.g.: .\Miniforge.ps1 -InstallDotnetInteractive

0 commit comments

Comments
 (0)