-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathinstall_windows.ps1
186 lines (154 loc) · 6.38 KB
/
install_windows.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
Set-StrictMode -Version Latest
function Is-SdkInstalled {
try {
$sdkPath = (Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows Kits\Installed Roots" -ErrorAction Stop).KitsRoot10
$sdkVersions = Get-ChildItem -Path "$sdkPath\bin" -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Name
if ($sdkVersions -match "10\.0\.(\d+)\.\d+") {
Write-Host "Windows SDK detected: $sdkVersions"
return $true
}
}
catch {
Write-Host "Windows SDK not found in registry."
}
return $false
}
function Install-BuildTools {
Write-Host "Installing Microsoft Visual C++ Build Tools and Windows SDK..."
$buildToolsUrl = "https://aka.ms/vs/17/release/vs_buildtools.exe"
$installerPath = "$env:TEMP\vs_buildtools.exe"
try {
Write-Host "Downloading Visual Studio Build Tools..."
Invoke-WebRequest -Uri $buildToolsUrl -OutFile $installerPath
Write-Host "Installing Visual Studio Build Tools (this may take a while)..."
$process = Start-Process -FilePath $installerPath -ArgumentList `
"--quiet", "--wait", "--norestart", "--nocache", `
"--installPath", "C:\BuildTools", `
"--add", "Microsoft.VisualStudio.Component.VC.Tools.x86.x64", `
"--add", "Microsoft.VisualStudio.Component.Windows10SDK.19041", `
"--add", "Microsoft.VisualStudio.Component.Windows11SDK.22000" `
-NoNewWindow -Wait -PassThru
if ($process.ExitCode -eq 0 -or $process.ExitCode -eq 3010) {
Write-Host "Visual Studio Build Tools and Windows SDK installed successfully."
return $true
}
Write-Error "Installation failed with exit code: $($process.ExitCode)"
return $false
}
catch {
Write-Error "Failed to install dependencies: $_"
return $false
}
finally {
Remove-Item $installerPath -Force -ErrorAction SilentlyContinue
}
}
function Install-ODBC {
Write-Host "Checking for ODBC Driver..."
$odbcRegistryPath = "HKLM:\SOFTWARE\ODBC\ODBCINST.INI\ODBC Driver 18 for SQL Server"
if (Test-Path $odbcRegistryPath) {
Write-Host "ODBC Driver 18 for SQL Server is already installed."
return $true
}
Write-Host "Downloading and Installing Microsoft ODBC Driver for SQL Server..."
try {
$odbcDownloadUrl = "https://go.microsoft.com/fwlink/?linkid=2280794"
$installerPath = "$env:TEMP\msodbcsql18.msi"
Invoke-WebRequest -Uri $odbcDownloadUrl -OutFile $installerPath
Start-Process -FilePath "msiexec.exe" -ArgumentList "/i $installerPath /quiet /norestart" -NoNewWindow -Wait
Remove-Item $installerPath -Force
Write-Host "ODBC Driver installed successfully."
# Update $PATH environment variable
Write-Host "Updating PATH environment variable for ODBC..."
$odbcLibPath = "C:\Program Files (x86)\Windows Kits\10\Lib\10.0.19041.0\um\x64"
if (-not (Test-Path $odbcLibPath)) {
Write-Warning "ODBC library path not found at $odbcLibPath. Ensure it is installed correctly."
}
else {
[Environment]::SetEnvironmentVariable("PATH", "$($env:PATH);$odbcLibPath", [EnvironmentVariableTarget]::Machine)
Write-Host "ODBC library path added to PATH: $odbcLibPath"
}
return $true
}
catch {
Write-Error "Failed to install ODBC Driver: $_"
return $false
}
}
Write-Host "Starting BTQuant installation script..."
Write-Host "Checking for Visual C++ Build Tools..."
if (-not (Test-Path "C:\BuildTools\VC\Auxiliary\Build\vcvarsall.bat")) {
Write-Host "Visual C++ Build Tools not found."
if (-not (Install-BuildTools)) {
Write-Error "Visual C++ Build Tools installation failed. Aborting."
exit 1
}
}
Write-Host "Checking for Windows SDK..."
if (-not (Is-SdkInstalled)) {
Write-Host "Windows SDK not found. Installing..."
if (-not (Install-BuildTools)) {
Write-Error "Windows SDK installation failed. Aborting."
exit 1
}
}
Write-Host "Checking for ODBC Driver..."
$odbcInstalled = Get-ItemProperty -Path "HKLM:\SOFTWARE\ODBC\ODBCINST.INI\ODBC Driver 18 for SQL Server" -ErrorAction SilentlyContinue
if (-not $odbcInstalled) {
Install-ODBC
} else {
Write-Host "ODBC Driver is already installed."
}
Write-Host "All dependencies verified. Proceeding with BTQuant installation..."
if (Test-Path "BTQuant") {
Write-Host "Removing previous BTQuant installation..."
Remove-Item -Recurse -Force "BTQuant"
}
Write-Host "Cloning BTQuant repository..."
git clone https://github.com/itsXactlY/BTQuant
Set-Location BTQuant
$repoRoot = Get-Location
Write-Host "Repository root: $repoRoot"
Write-Host "Setting up virtual environment..."
python -m venv .venv
& ".\.venv\Scripts\Activate.ps1"
Write-Host "Upgrading pip, setuptools, and wheel..."
python -m pip install --upgrade pip setuptools wheel
$venvSitePackages = Join-Path $repoRoot ".venv\Lib\site-packages"
Write-Host "Using virtual environment site-packages at: $venvSitePackages"
Write-Host "Installing dependencies..."
if (Test-Path "dependencies") {
Set-Location "dependencies"
} else {
Write-Error "Dependencies folder not found."
exit 1
}
Write-Host "Installing pybind11..."
python -m pip install --target $venvSitePackages pybind11
$localPackages = @(".", "fastquant", "BTQ_Exchanges", "MsSQL")
foreach ($package in $localPackages) {
Write-Host "Installing $package..."
$packagePath = Join-Path (Get-Location) $package
if (Test-Path $packagePath) {
Push-Location $packagePath
python -m pip install --target $venvSitePackages .
Pop-Location
}
else {
Write-Host "Warning: Package folder for $package not found. Skipping..."
}
}
Write-Host "Checking for fast_mssql.pyd..."
$pydFile = Get-ChildItem -Recurse -Filter "fast_mssql*.pyd" | Select-Object -First 1
if ($pydFile) {
$targetDir = Join-Path $venvSitePackages "fastquant\data\mssql\MsSQL"
New-Item -ItemType Directory -Force -Path $targetDir | Out-Null
Copy-Item $pydFile.FullName -Destination $targetDir -Force
}
Set-Location $repoRoot
Write-Host "`nBTQuant installation complete!`n"
Write-Host "To use BTQuant in a new PowerShell session:"
Write-Host "1. cd BTQuant"
Write-Host "2. .\.venv\Scripts\Activate.ps1"
Write-Host "3. Start using BTQuant with Python"
Read-Host -Prompt "Press Enter to exit"