-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall_julia.py
70 lines (59 loc) · 2.35 KB
/
install_julia.py
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
import os
import platform
import urllib.request
import tarfile
import zipfile
import shutil
def install_julia(version="1.6.7", install_dir="venv"):
system = platform.system().lower()
arch = platform.machine()
# Map system and architecture to Julia binaries
if system == "linux" and arch == "x86_64":
filename = f"julia-{version}-linux-x86_64.tar.gz"
elif system == "darwin" and arch == "x86_64":
filename = f"julia-{version}-mac64.dmg"
elif system == "darwin" and arch == "arm64":
filename = f"julia-{version}-mac64-arm64.dmg"
elif system == "windows" and arch in {"AMD64", "x86_64"}:
filename = f"julia-{version}-win64.zip"
else:
raise RuntimeError(f"Unsupported platform: {system} {arch}")
# Construct URL and paths
base_url = "https://julialang-s3.julialang.org/bin"
url = f"{base_url}/linux/x64/1.6/{filename}"
target_path = os.path.join(install_dir, filename)
extract_path = os.path.join(install_dir, f"julia-{version}")
# Create installation directory
os.makedirs(install_dir, exist_ok=True)
# Download Julia archive
print(f"Downloading Julia {version} from {url}...")
urllib.request.urlretrieve(url, target_path)
print(f"Downloaded {filename} to {target_path}")
# Extract archive
print(f"Extracting {filename}...")
if filename.endswith(".tar.gz"):
with tarfile.open(target_path, "r:gz") as tar:
tar.extractall(install_dir)
elif filename.endswith(".zip"):
with zipfile.ZipFile(target_path, "r") as zip_ref:
zip_ref.extractall(install_dir)
else:
raise RuntimeError("Unsupported archive format. Install manually.")
# Clean up
os.remove(target_path)
print(f"Extracted Julia to {extract_path}")
# Add to PATH (optional, for current session)
julia_bin = os.path.join(extract_path, "bin")
if os.path.exists(julia_bin):
os.environ["PATH"] = f"{julia_bin}:{os.environ['PATH']}"
print(f"Added {julia_bin} to PATH.")
else:
print("Julia bin directory not found.")
# Verify installation
print("Verifying Julia installation...")
if shutil.which("julia"):
os.system("julia --version")
else:
print("Julia installation complete, but could not find 'julia' in PATH.")
# Run the script
install_julia()