Skip to content

Commit e9cf06a

Browse files
committed
Added conda installer script for windows powershell
1 parent 6069467 commit e9cf06a

File tree

1 file changed

+113
-0
lines changed

1 file changed

+113
-0
lines changed
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# Define variables
2+
$condaInstallerUrl = "https://repo.anaconda.com/miniconda/Miniconda3-latest-Windows-x86_64.exe"
3+
$condaInstallerPath = "$env:TEMP\Miniconda3-latest-Windows-x86_64.exe"
4+
$condaPath = "$env:USERPROFILE\Miniconda3"
5+
$envName = "oi"
6+
$pythonVersion = "3.11.7"
7+
$packageName = "open-interpreter litellm openai"
8+
$desktopPath = [System.IO.Path]::Combine([System.Environment]::GetFolderPath('Desktop'), 'Open Interpreter.lnk')
9+
$condaExePath = "$condaPath\Scripts\conda.exe"
10+
11+
# URL of the .ico file
12+
# $icoUrl = "https://raw.githubusercontent.com/OpenInterpreter/open-interpreter/main/docs/assets/favicon.ico"
13+
$icoUrl = "https://raw.githubusercontent.com/CyanideByte/open-interpreter/conda-installer/docs/assets/favicon.ico"
14+
$icoPath = "$env:TEMP\open-interpreter.ico"
15+
16+
# Function to download a file with progress
17+
function DownloadFileWithProgress {
18+
param (
19+
[string]$url,
20+
[string]$output
21+
)
22+
23+
$request = [System.Net.HttpWebRequest]::Create($url)
24+
$response = $request.GetResponse()
25+
$totalLength = $response.ContentLength
26+
$readBytes = 0
27+
$buffer = New-Object byte[] 1024
28+
$percentComplete = 0
29+
30+
$stream = $response.GetResponseStream()
31+
$fileStream = New-Object IO.FileStream ($output, [System.IO.FileMode]::Create)
32+
33+
try {
34+
while (($read = $stream.Read($buffer, 0, $buffer.Length)) -gt 0) {
35+
$fileStream.Write($buffer, 0, $read)
36+
$readBytes += $read
37+
$newPercentComplete = [math]::Round(($readBytes / $totalLength) * 100)
38+
39+
if ($newPercentComplete -ne $percentComplete) {
40+
$percentComplete = $newPercentComplete
41+
Write-Progress -Activity "Downloading Miniconda Installer" -Status "$percentComplete% Complete" -PercentComplete $percentComplete
42+
}
43+
}
44+
} finally {
45+
$fileStream.Close()
46+
$stream.Close()
47+
}
48+
49+
Write-Progress -Activity "Downloading Miniconda Installer" -Completed
50+
}
51+
52+
# Download the .ico file
53+
Write-Host "Downloading icon file..."
54+
DownloadFileWithProgress -url $icoUrl -output $icoPath
55+
56+
# Function to check if Conda is installed
57+
function Test-CondaInstalled {
58+
try {
59+
& conda --version > $null 2>&1
60+
return $true
61+
} catch {
62+
return $false
63+
}
64+
}
65+
66+
# Check if Conda is installed
67+
if (-Not (Test-CondaInstalled)) {
68+
Write-Host "Conda is not installed."
69+
70+
# Download Miniconda installer if not already downloaded
71+
if (-Not (Test-Path $condaInstallerPath)) {
72+
DownloadFileWithProgress -url $condaInstallerUrl -output $condaInstallerPath
73+
} else {
74+
Write-Host "Miniconda installer already downloaded."
75+
}
76+
77+
# Run the Miniconda installer with messages before and after
78+
Write-Host "Starting Miniconda installation... (there will be no progress bar)"
79+
Start-Process -Wait -FilePath $condaInstallerPath -ArgumentList "/InstallationType=JustMe", "/AddToPath=1", "/RegisterPython=0", "/S", "/D=$condaPath"
80+
Write-Host "Miniconda installation complete."
81+
82+
# Ensure Conda is in the PATH for the current session
83+
$env:Path += ";$condaPath\Scripts;$condaPath"
84+
} else {
85+
Write-Host "Conda is already installed."
86+
}
87+
88+
# Create and activate the Conda environment, and show progress
89+
Write-Host "Creating Conda environment '$envName'..."
90+
& $condaExePath create -n $envName python=$pythonVersion -y
91+
Write-Host "Conda environment '$envName' created."
92+
93+
# Dynamically generate the user's paths for the shortcut
94+
$userCondaScriptsPath = "$condaPath\Scripts"
95+
$userEnvName = $envName
96+
97+
# Create a shortcut on the desktop to activate the environment, install OpenInterpreter, and run it
98+
$targetPath = "$env:SystemRoot\System32\cmd.exe"
99+
$arguments = "/K `"$userCondaScriptsPath\activate.bat` $userEnvName && echo Updating Open Interpreter && pip install -U $packageName && cls && echo Launching Open Interpreter && interpreter`""
100+
101+
$shell = New-Object -ComObject WScript.Shell
102+
$shortcut = $shell.CreateShortcut($desktopPath)
103+
$shortcut.TargetPath = $targetPath
104+
$shortcut.Arguments = $arguments
105+
$shortcut.WorkingDirectory = $env:USERPROFILE
106+
$shortcut.WindowStyle = 1 # Normal window
107+
$shortcut.IconLocation = $icoPath
108+
$shortcut.Save()
109+
110+
Write-Host "Shortcut 'Open Interpreter.lnk' has been created on the desktop with the custom icon."
111+
112+
# Open the shortcut
113+
Start-Process -FilePath $desktopPath

0 commit comments

Comments
 (0)