|
| 1 | +#!/bin/sh |
| 2 | +# Xinference installer |
| 3 | +# |
| 4 | +# curl -fsSL https://raw.githubusercontent.com/xorbitsai/inference/main/scripts/install.sh | sh |
| 5 | +# |
| 6 | +# Installs the `xinference` package as an isolated uv tool, so nothing touches |
| 7 | +# your system Python and PEP 668 (externally-managed-environment) never bites. |
| 8 | +# On success the `xinference` / `xinference-local` commands are available; start |
| 9 | +# the server and open the Web UI. |
| 10 | +# |
| 11 | +# Options (environment variables): |
| 12 | +# XINFERENCE_VERSION pin a specific version, e.g. XINFERENCE_VERSION=1.8.1 |
| 13 | +# XINFERENCE_EXTRAS install optional backends, e.g. XINFERENCE_EXTRAS=all |
| 14 | +# or XINFERENCE_EXTRAS=vllm,transformers (default: none). |
| 15 | +# Note: some extras (e.g. vllm) require Linux + CUDA and |
| 16 | +# may fail to install on macOS or CPU-only machines. |
| 17 | +# |
| 18 | +# Prefer not to pipe curl into sh? The equivalent manual install is: |
| 19 | +# uv tool install xinference # or, in a venv: pip install xinference |
| 20 | +set -eu |
| 21 | + |
| 22 | +# The user's PATH before this script mutates it (below, when bootstrapping uv). |
| 23 | +# Used at the end to warn correctly about whether the parent shell will find the |
| 24 | +# installed command. |
| 25 | +ORIG_PATH="$PATH" |
| 26 | + |
| 27 | +APP="xinference" |
| 28 | +# Command used to start the server locally (the `xinference` command itself is |
| 29 | +# the client CLI; `xinference-local` boots a standalone supervisor + worker). |
| 30 | +SERVE_CMD="xinference-local" |
| 31 | +PORT="9997" |
| 32 | + |
| 33 | +info() { printf '\033[1;34m==>\033[0m %s\n' "$1"; } |
| 34 | +warn() { printf '\033[1;33mwarning:\033[0m %s\n' "$1" >&2; } |
| 35 | +err() { |
| 36 | + printf '\033[1;31merror:\033[0m %s\n' "$1" >&2 |
| 37 | + exit 1 |
| 38 | +} |
| 39 | + |
| 40 | +# uv supports Linux and macOS. Windows users should use pip in a venv. |
| 41 | +os="$(uname -s)" |
| 42 | +case "$os" in |
| 43 | + Linux | Darwin) ;; |
| 44 | + *) err "Unsupported OS '$os'. On Windows, install with: pip install \"$APP[all]\" (in a virtualenv)." ;; |
| 45 | +esac |
| 46 | + |
| 47 | +# Ensure uv is available (isolates the install; avoids system-Python/PEP 668). |
| 48 | +if ! command -v uv >/dev/null 2>&1; then |
| 49 | + info "Installing uv (Python tool manager)..." |
| 50 | + curl -LsSf https://astral.sh/uv/install.sh | sh |
| 51 | + # uv installs into ~/.local/bin (or ~/.cargo/bin on older installers); make it |
| 52 | + # visible to the rest of this script without requiring a new shell. |
| 53 | + for d in "$HOME/.local/bin" "$HOME/.cargo/bin"; do |
| 54 | + [ -d "$d" ] && PATH="$d:$PATH" |
| 55 | + done |
| 56 | + export PATH |
| 57 | +fi |
| 58 | +command -v uv >/dev/null 2>&1 || err "uv not found on PATH after install; open a new shell and re-run." |
| 59 | + |
| 60 | +# Build the package spec: name[extras]==version, with each part optional. |
| 61 | +spec="$APP" |
| 62 | +if [ -n "${XINFERENCE_EXTRAS:-}" ]; then |
| 63 | + spec="$spec[$XINFERENCE_EXTRAS]" |
| 64 | +fi |
| 65 | +if [ -n "${XINFERENCE_VERSION:-}" ]; then |
| 66 | + # Strip a leading 'v' (e.g. v1.8.1 -> 1.8.1) so a git-tag-style value works. |
| 67 | + version="${XINFERENCE_VERSION#v}" |
| 68 | + [ -n "$version" ] || err "XINFERENCE_VERSION='$XINFERENCE_VERSION' is not a valid version." |
| 69 | + spec="$spec==$version" |
| 70 | +fi |
| 71 | + |
| 72 | +info "Installing $spec ..." |
| 73 | +uv tool install --upgrade "$spec" |
| 74 | + |
| 75 | +printf '\n' |
| 76 | +info "Installed. Next steps:" |
| 77 | +printf '\n' |
| 78 | +printf ' Start the server: %s\n' "$SERVE_CMD" |
| 79 | +printf ' Open the Web UI: http://127.0.0.1:%s\n' "$PORT" |
| 80 | +if [ -z "${XINFERENCE_EXTRAS:-}" ]; then |
| 81 | + printf '\n' |
| 82 | + printf ' This installed the base package. To add an inference backend later, e.g.:\n' |
| 83 | + printf ' uv tool install --upgrade "%s[transformers]" # PyTorch / transformers\n' "$APP" |
| 84 | + printf ' uv tool install --upgrade "%s[vllm]" # vLLM (Linux + CUDA)\n' "$APP" |
| 85 | + printf ' uv tool install --upgrade "%s[mlx]" # MLX (Apple silicon)\n' "$APP" |
| 86 | + printf ' Or reinstall everything with XINFERENCE_EXTRAS=all.\n' |
| 87 | +fi |
| 88 | +printf '\n' |
| 89 | + |
| 90 | +# Check against the parent shell's original PATH. Scope the PATH override with a |
| 91 | +# subshell rather than a leading `PATH=... command -v` assignment: the latter's |
| 92 | +# effect on a shell built-in is not clearly specified by POSIX, so the subshell |
| 93 | +# form is unambiguous across shells. |
| 94 | +if ! ( PATH="$ORIG_PATH"; command -v "$SERVE_CMD" ) >/dev/null 2>&1; then |
| 95 | + warn "'$SERVE_CMD' is not on your PATH in this shell yet." |
| 96 | + if ( PATH="$ORIG_PATH"; command -v uv ) >/dev/null 2>&1; then |
| 97 | + warn "Run 'uv tool update-shell' and open a new terminal, then run '$SERVE_CMD'." |
| 98 | + else |
| 99 | + # uv was just installed by this script and isn't on the parent shell's PATH. |
| 100 | + warn "Open a new terminal, or run: export PATH=\"\$HOME/.local/bin:\$PATH\"" |
| 101 | + fi |
| 102 | +fi |
0 commit comments