-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathportablepy.ps1
More file actions
79 lines (55 loc) · 2.29 KB
/
portablepy.ps1
File metadata and controls
79 lines (55 loc) · 2.29 KB
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
param ($source, $destination, $pythonVersion)
if (!$source) {
$source = 'https://www.python.org/ftp/python/3.9.10/python-3.9.10-embed-amd64.zip'
}
if (!$pythonVersion) {
$source -match '.+\/python-(\d+)\.(\d+)\..+'
$Matches
$pythonVersion = "python$($Matches[1])$($Matches[2])"
}
if (!$destination) {
$destination = '.\'
}
# Fixes an error if the user doesn't put a backslash at the end of the url
$destination += "\"
"You're installing $($pythonVersion) into $($destination)"
# Destination to save the file
$package = "$($destination)embedpython.zip"
#Download the file
"Downloading package from $($source)"
Invoke-WebRequest -Uri $source -OutFile $package
Expand-Archive -Path $package -DestinationPath $destination
Expand-Archive -Path "$($destination)$($pythonVersion).zip" -DestinationPath "$($destination)$($pythonVersion)"
"Writing $($pythonVersion)._pth"
".\$($pythonVersion)
.\Scripts
.
import site
" | Out-File -FilePath "$($destination)$($pythonVersion)._pth" -encoding ASCII
"Writing sitecustomize.py"
"import sys, os
sys.path = []
path = os.getcwd()
sys.path.append('')
sys.path.append(os.path.join(path, `"$($pythonVersion)`"))
sys.path.append(os.path.join(path, `"Scripts`"))
sys.path.append(path)
sys.path.append(os.path.join(path, `"lib`", `"site-packages`"))
" | Out-File -FilePath "$($destination)sitecustomize.py" -encoding ASCII
"Creating DLLs dir"
mkdir "$($destination)DLLs"
"Installing PIP"
"You will see some warning about the $($destination)Scripts folder not on your SYSTEM PATH. That is NORMAL!"
Invoke-WebRequest -OutFile "$($destination)get-pip.py" "https://bootstrap.pypa.io/get-pip.py"
& "$($destination)python.exe" "$($destination)get-pip.py"
"Cleaning up"
Remove-Item -Path $package -Confirm:$false -Force
Remove-Item -Path "$($destination)$($pythonVersion).zip" -Confirm:$false -Force
Remove-Item -Path "$($destination)get-pip.py" -Confirm:$false -Force
"Done!
INFO:
You can install module by running .\python.exe -m pip YOURMODULE
Always use full path or relative path with with . or .. (e.g. .\python.exe) to run your portable python.
Otherwise, you may trigger the python that has been installed on your system (if any) instead.
TO DO:
You can now remove this .ps1 file manually!"