From 51cde19b39ef2053ea30c44a5e23de89082b1caf Mon Sep 17 00:00:00 2001 From: Roman Date: Tue, 10 Jun 2025 10:41:35 -0700 Subject: [PATCH 1/3] improve script (add venv) --- scripts/install.sh | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/scripts/install.sh b/scripts/install.sh index 6171d18761..145afabeb6 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -73,7 +73,7 @@ cd "/usr" || exit 1 linux_install_pre() { sudo apt-get update - sudo apt-get install --no-install-recommends --no-install-suggests -y apt-utils curl git cmake build-essential + sudo apt-get install --no-install-recommends --no-install-suggests -y apt-utils curl git cmake build-essential python3-dev python3-venv exit_on_error $? } @@ -103,6 +103,11 @@ linux_install_bittensor() { ohai "Cloning bittensor@master into ~/.bittensor/bittensor" mkdir -p ~/.bittensor/bittensor git clone https://github.com/opentensor/bittensor.git ~/.bittensor/bittensor/ 2> /dev/null || (cd ~/.bittensor/bittensor/ ; git fetch origin master ; git checkout master ; git pull --ff-only ; git reset --hard ; git clean -xdf) + + ohai "Creating Python virtual environment" + python3 -m venv ~/.bittensor/venv + source ~/.bittensor/venv/bin/activate + ohai "Installing bittensor" $python -m pip install -e ~/.bittensor/bittensor/ $python -m pip install -U bittensor-cli @@ -166,6 +171,11 @@ mac_update_pip() { mac_install_bittensor() { ohai "Cloning bittensor into ~/.bittensor/bittensor" git clone https://github.com/opentensor/bittensor.git ~/.bittensor/bittensor/ 2> /dev/null || (cd ~/.bittensor/bittensor/ ; git fetch origin master ; git checkout master ; git pull --ff-only ; git reset --hard; git clean -xdf) + + ohai "Creating Python virtual environment" + python3 -m venv ~/.bittensor/venv + source ~/.bittensor/venv/bin/activate + ohai "Installing bittensor" $python -m pip install -e ~/.bittensor/bittensor/ $python -m pip install -U bittensor-cli @@ -178,7 +188,7 @@ OS="$(uname)" if [[ "$OS" == "Linux" ]]; then which -s apt-get - if [[ $? == 0 ]] ; then + if [[ $? != 0 ]] ; then abort "This linux based install requires apt-get. To run with other distros (centos, arch, etc), you will need to manually install the requirements" fi echo """ From 5d5e098741fcf555c50a9ecd0c7e161942587478 Mon Sep 17 00:00:00 2001 From: Roman Date: Tue, 10 Jun 2025 11:07:36 -0700 Subject: [PATCH 2/3] improve script --- scripts/install.sh | 55 ++++++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 26 deletions(-) diff --git a/scripts/install.sh b/scripts/install.sh index 145afabeb6..9152d0c0a7 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -1,8 +1,7 @@ - #!/bin/bash set -u -# enable command completion +# enable command completion set -o history -o histexpand python="python3" @@ -34,7 +33,6 @@ wait_for_user() { echo echo "Press RETURN to continue or any other key to abort" getc c - # we test for \r and \n because some stuff does \r instead if ! [[ "$c" == $'\r' || "$c" == $'\n' ]]; then exit 1 fi @@ -67,13 +65,9 @@ ohai() { printf "${tty_blue}==>${tty_bold} %s${tty_reset}\n" "$(shell_join "$@")" } -# Things can fail later if `pwd` doesn't exist. -# Also sudo prints a warning message for no good reason -cd "/usr" || exit 1 - linux_install_pre() { - sudo apt-get update - sudo apt-get install --no-install-recommends --no-install-suggests -y apt-utils curl git cmake build-essential python3-dev python3-venv + sudo apt-get update + sudo apt-get install --no-install-recommends --no-install-suggests -y apt-utils curl git cmake build-essential exit_on_error $? } @@ -86,10 +80,10 @@ linux_install_python() { ohai "Updating python" sudo apt-get install --only-upgrade $python fi - exit_on_error $? + exit_on_error $? ohai "Installing python tools" - sudo apt-get install --no-install-recommends --no-install-suggests -y $python-pip $python-dev - exit_on_error $? + sudo apt-get install --no-install-recommends --no-install-suggests -y python3-pip python3-dev python3-venv + exit_on_error $? } linux_update_pip() { @@ -102,16 +96,21 @@ linux_update_pip() { linux_install_bittensor() { ohai "Cloning bittensor@master into ~/.bittensor/bittensor" mkdir -p ~/.bittensor/bittensor - git clone https://github.com/opentensor/bittensor.git ~/.bittensor/bittensor/ 2> /dev/null || (cd ~/.bittensor/bittensor/ ; git fetch origin master ; git checkout master ; git pull --ff-only ; git reset --hard ; git clean -xdf) + git clone https://github.com/opentensor/bittensor.git ~/.bittensor/bittensor/ 2> /dev/null || \ + (cd ~/.bittensor/bittensor/ ; git fetch origin master ; git checkout master ; git pull --ff-only ; git reset --hard ; git clean -xdf) ohai "Creating Python virtual environment" python3 -m venv ~/.bittensor/venv + $HOME/.bittensor/venv/bin/python -m ensurepip --upgrade source ~/.bittensor/venv/bin/activate + python="$HOME/.bittensor/venv/bin/python" ohai "Installing bittensor" + $python -m pip install --upgrade pip $python -m pip install -e ~/.bittensor/bittensor/ $python -m pip install -U bittensor-cli - exit_on_error $? + exit_on_error $? + deactivate } linux_increase_ulimit(){ @@ -119,13 +118,12 @@ linux_increase_ulimit(){ prlimit --pid=$PPID --nofile=1000000 } - mac_install_xcode() { which -s xcode-select if [[ $? != 0 ]] ; then ohai "Installing xcode:" xcode-select --install - exit_on_error $? + exit_on_error $? fi } @@ -138,7 +136,7 @@ mac_install_brew() { ohai "Updating brew:" brew update --verbose fi - exit_on_error $? + exit_on_error $? } mac_install_cmake() { @@ -158,7 +156,7 @@ mac_install_python() { brew list python@3 &>/dev/null || brew install python@3; ohai "Updating python3" brew upgrade python@3 - exit_on_error $? + exit_on_error $? } mac_update_pip() { @@ -170,16 +168,20 @@ mac_update_pip() { mac_install_bittensor() { ohai "Cloning bittensor into ~/.bittensor/bittensor" - git clone https://github.com/opentensor/bittensor.git ~/.bittensor/bittensor/ 2> /dev/null || (cd ~/.bittensor/bittensor/ ; git fetch origin master ; git checkout master ; git pull --ff-only ; git reset --hard; git clean -xdf) + git clone https://github.com/opentensor/bittensor.git ~/.bittensor/bittensor/ 2> /dev/null || \ + (cd ~/.bittensor/bittensor/ ; git fetch origin master ; git checkout master ; git pull --ff-only ; git reset --hard; git clean -xdf) ohai "Creating Python virtual environment" python3 -m venv ~/.bittensor/venv + $HOME/.bittensor/venv/bin/python -m ensurepip --upgrade source ~/.bittensor/venv/bin/activate + python="$HOME/.bittensor/venv/bin/python" ohai "Installing bittensor" + $python -m pip install --upgrade pip $python -m pip install -e ~/.bittensor/bittensor/ $python -m pip install -U bittensor-cli - exit_on_error $? + exit_on_error $? deactivate } @@ -191,8 +193,9 @@ if [[ "$OS" == "Linux" ]]; then if [[ $? != 0 ]] ; then abort "This linux based install requires apt-get. To run with other distros (centos, arch, etc), you will need to manually install the requirements" fi + echo """ - + ██████╗░██╗████████╗████████╗███████╗███╗░░██╗░██████╗░█████╗░██████╗░ ██╔══██╗██║╚══██╔══╝╚══██╔══╝██╔════╝████╗░██║██╔════╝██╔══██╗██╔══██╗ ██████╦╝██║░░░██║░░░░░░██║░░░█████╗░░██╔██╗██║╚█████╗░██║░░██║██████╔╝ @@ -270,7 +273,7 @@ fi # Use the shell's audible bell. if [[ -t 1 ]]; then -printf "\a" + printf "\a" fi echo "" @@ -299,12 +302,12 @@ echo " $ btcli w new_hotkey" echo " $ btcli w list" echo " $ btcli s register" echo "" +echo "- Check Bittensor SDK version" +echo " $ python -m bittensor" +echo "" echo "- Use the Python API" echo " $ python3"echo " >> import bittensor" echo "" -echo "- Join the discussion: " +echo "- Join the discussion:" echo " ${tty_underline}https://discord.gg/3rUr6EcvbB${tty_reset}" echo "" - - - From ec6de223b03e9e06f79469f1d055f8e77223786d Mon Sep 17 00:00:00 2001 From: Roman Date: Tue, 10 Jun 2025 11:16:03 -0700 Subject: [PATCH 3/3] improve script --- scripts/install.sh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/scripts/install.sh b/scripts/install.sh index 9152d0c0a7..73c5c4945c 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -87,12 +87,10 @@ linux_install_python() { } linux_update_pip() { - PYTHONPATH=$(which $python) - ohai "You are using python@ $PYTHONPATH$" - ohai "Installing python tools" - $python -m pip install --upgrade pip + ohai "Skipping pip upgrade in system Python (PEP 668). Will upgrade inside virtual environment." } + linux_install_bittensor() { ohai "Cloning bittensor@master into ~/.bittensor/bittensor" mkdir -p ~/.bittensor/bittensor