forked from Shiyong-Tan/pyOpenLPT
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall_mac.command
More file actions
138 lines (120 loc) · 4.33 KB
/
install_mac.command
File metadata and controls
138 lines (120 loc) · 4.33 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
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
#!/bin/bash
echo "=========================================="
echo " OpenLPT One-Click Installer"
echo "=========================================="
echo ""
echo "This script will:"
echo "1. Create a Conda environment named 'OpenLPT'"
echo "2. Install all dependencies"
echo "3. Install the OpenLPT package"
echo ""
read -p "Press enter to continue..."
# --- Xcode Command Line Tools Check ---
echo ""
echo "[0.5/4] Checking for Xcode Command Line Tools..."
if ! xcode-select -p &> /dev/null; then
echo ""
echo "[ERROR] Xcode Command Line Tools not found!"
echo " These are REQUIRED for compiling C++ extensions on macOS."
echo ""
echo "Please run the following command in your terminal:"
echo " xcode-select --install"
echo ""
echo "Follow the pop-up prompts to install, then RUN THIS SCRIPT AGAIN."
echo "================================================================"
read -p "Press Enter to exit..."
exit 1
else
echo "[OK] Xcode Command Line Tools found."
fi
# --- libomp (OpenMP) Check ---
echo ""
echo "[0.7/4] Checking for libomp (OpenMP Support)..."
if ! command -v brew &> /dev/null; then
echo "[INFO] Homebrew not found. We will rely on Conda for OpenMP."
elif ! brew list libomp &> /dev/null; then
echo "[INFO] libomp not found via brew. Recommending: brew install libomp"
# Optional: brew install libomp
fi
# --------------------------------------
cd "$(dirname "$0")"
# Check if conda is installed
if ! command -v conda &> /dev/null; then
echo ""
echo "[!] Conda/Mamba not found."
echo "[!] Should I automatically download and install Miniforge3 (Minimal Conda + Mamba)?"
echo " Target: $HOME/miniforge3"
echo ""
read -p "Press ENTER to install Miniforge3 (or Ctrl+C to cancel)..."
echo ""
echo "[0/3] Installing Miniforge3..."
ARCH=$(uname -m)
INSTALLER="Miniforge3-MacOSX-${ARCH}.sh"
URL="https://github.com/conda-forge/miniforge/releases/latest/download/${INSTALLER}"
echo "Downloading ${URL}..."
curl -L -O "$URL"
echo "Installing to $HOME/miniforge3..."
bash "$INSTALLER" -b -p "$HOME/miniforge3"
rm "$INSTALLER"
# Initialize for future shells
"$HOME/miniforge3/bin/conda" init zsh
"$HOME/miniforge3/bin/conda" init bash
# Activate for current script
source "$HOME/miniforge3/bin/activate"
echo "Miniforge3 installed successfully!"
fi
echo ""
echo "[1/3] Creating Conda Environment 'OpenLPT'..."
conda create -n OpenLPT python=3.10 -y
echo ""
echo "[2/3] Activating Environment..."
# Try to find conda hook
CONDA_BASE=$(conda info --base)
if [ -f "$CONDA_BASE/etc/profile.d/conda.sh" ]; then
source "$CONDA_BASE/etc/profile.d/conda.sh"
conda activate OpenLPT
else
echo "[Warning] Could not find conda.sh. Assuming environment is correct or manual activation needed."
fi
echo ""
echo "[3/3] Installing Dependencies..."
mamba install -c conda-forge --file requirements.txt -y
if [ $? -ne 0 ]; then
echo "[Error] Mamba install failed."
echo "NOTE: This project requires mamba."
read -p "Press enter to exit"
exit 1
fi
echo ""
echo "[3.5/4] Configuring Compiler Flags for macOS (OpenMP)..."
# 1. Force a clean build to ensure CMake picks up new flags
rm -rf build/
rm -rf _skbuild/ # just in case
# 2. Set environment variables that CMake respects automatically
# If brew libomp exists, it's usually more reliable
if command -v brew &> /dev/null && [ -d "$(brew --prefix libomp)" ]; then
LIBOMP_PATH=$(brew --prefix libomp)
export OpenMP_ROOT="$LIBOMP_PATH"
export LDFLAGS="-L$LIBOMP_PATH/lib -Wl,-rpath,$LIBOMP_PATH/lib $LDFLAGS"
export CPPFLAGS="-I$LIBOMP_PATH/include $CPPFLAGS"
export CXXFLAGS="-I$LIBOMP_PATH/include $CXXFLAGS"
else
export LDFLAGS="-L$CONDA_PREFIX/lib -Wl,-rpath,$CONDA_PREFIX/lib $LDFLAGS"
export CPPFLAGS="-I$CONDA_PREFIX/include $CPPFLAGS"
export CXXFLAGS="-I$CONDA_PREFIX/include $CXXFLAGS"
fi
echo "Environment configured for OpenMP."
echo ""
echo "[4/4] Installing OpenLPT..."
pip install . --no-build-isolation
if [ $? -ne 0 ]; then
echo "[Error] Pip install failed."
read -p "Press enter to exit"
exit 1
fi
echo ""
echo "=========================================="
echo " Installation Complete!"
echo " Launching OpenLPT GUI..."
echo "=========================================="
python GUI.py