Skip to content

Commit 23ebd0f

Browse files
authored
Merge pull request #2914 from opentensor/fix/roman/install.sh
improve `scripts/install.sh`
2 parents 9297101 + ec6de22 commit 23ebd0f

File tree

1 file changed

+41
-30
lines changed

1 file changed

+41
-30
lines changed

scripts/install.sh

Lines changed: 41 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
21
#!/bin/bash
32
set -u
43

5-
# enable command completion
4+
# enable command completion
65
set -o history -o histexpand
76

87
python="python3"
@@ -34,7 +33,6 @@ wait_for_user() {
3433
echo
3534
echo "Press RETURN to continue or any other key to abort"
3635
getc c
37-
# we test for \r and \n because some stuff does \r instead
3836
if ! [[ "$c" == $'\r' || "$c" == $'\n' ]]; then
3937
exit 1
4038
fi
@@ -67,12 +65,8 @@ ohai() {
6765
printf "${tty_blue}==>${tty_bold} %s${tty_reset}\n" "$(shell_join "$@")"
6866
}
6967

70-
# Things can fail later if `pwd` doesn't exist.
71-
# Also sudo prints a warning message for no good reason
72-
cd "/usr" || exit 1
73-
7468
linux_install_pre() {
75-
sudo apt-get update
69+
sudo apt-get update
7670
sudo apt-get install --no-install-recommends --no-install-suggests -y apt-utils curl git cmake build-essential
7771
exit_on_error $?
7872
}
@@ -86,41 +80,48 @@ linux_install_python() {
8680
ohai "Updating python"
8781
sudo apt-get install --only-upgrade $python
8882
fi
89-
exit_on_error $?
83+
exit_on_error $?
9084
ohai "Installing python tools"
91-
sudo apt-get install --no-install-recommends --no-install-suggests -y $python-pip $python-dev
92-
exit_on_error $?
85+
sudo apt-get install --no-install-recommends --no-install-suggests -y python3-pip python3-dev python3-venv
86+
exit_on_error $?
9387
}
9488

9589
linux_update_pip() {
96-
PYTHONPATH=$(which $python)
97-
ohai "You are using python@ $PYTHONPATH$"
98-
ohai "Installing python tools"
99-
$python -m pip install --upgrade pip
90+
ohai "Skipping pip upgrade in system Python (PEP 668). Will upgrade inside virtual environment."
10091
}
10192

93+
10294
linux_install_bittensor() {
10395
ohai "Cloning bittensor@master into ~/.bittensor/bittensor"
10496
mkdir -p ~/.bittensor/bittensor
105-
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)
97+
git clone https://github.com/opentensor/bittensor.git ~/.bittensor/bittensor/ 2> /dev/null || \
98+
(cd ~/.bittensor/bittensor/ ; git fetch origin master ; git checkout master ; git pull --ff-only ; git reset --hard ; git clean -xdf)
99+
100+
ohai "Creating Python virtual environment"
101+
python3 -m venv ~/.bittensor/venv
102+
$HOME/.bittensor/venv/bin/python -m ensurepip --upgrade
103+
source ~/.bittensor/venv/bin/activate
104+
python="$HOME/.bittensor/venv/bin/python"
105+
106106
ohai "Installing bittensor"
107+
$python -m pip install --upgrade pip
107108
$python -m pip install -e ~/.bittensor/bittensor/
108109
$python -m pip install -U bittensor-cli
109-
exit_on_error $?
110+
exit_on_error $?
111+
deactivate
110112
}
111113

112114
linux_increase_ulimit(){
113115
ohai "Increasing ulimit to 1,000,000"
114116
prlimit --pid=$PPID --nofile=1000000
115117
}
116118

117-
118119
mac_install_xcode() {
119120
which -s xcode-select
120121
if [[ $? != 0 ]] ; then
121122
ohai "Installing xcode:"
122123
xcode-select --install
123-
exit_on_error $?
124+
exit_on_error $?
124125
fi
125126
}
126127

@@ -133,7 +134,7 @@ mac_install_brew() {
133134
ohai "Updating brew:"
134135
brew update --verbose
135136
fi
136-
exit_on_error $?
137+
exit_on_error $?
137138
}
138139

139140
mac_install_cmake() {
@@ -153,7 +154,7 @@ mac_install_python() {
153154
brew list python@3 &>/dev/null || brew install python@3;
154155
ohai "Updating python3"
155156
brew upgrade python@3
156-
exit_on_error $?
157+
exit_on_error $?
157158
}
158159

159160
mac_update_pip() {
@@ -165,11 +166,20 @@ mac_update_pip() {
165166

166167
mac_install_bittensor() {
167168
ohai "Cloning bittensor into ~/.bittensor/bittensor"
168-
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)
169+
git clone https://github.com/opentensor/bittensor.git ~/.bittensor/bittensor/ 2> /dev/null || \
170+
(cd ~/.bittensor/bittensor/ ; git fetch origin master ; git checkout master ; git pull --ff-only ; git reset --hard; git clean -xdf)
171+
172+
ohai "Creating Python virtual environment"
173+
python3 -m venv ~/.bittensor/venv
174+
$HOME/.bittensor/venv/bin/python -m ensurepip --upgrade
175+
source ~/.bittensor/venv/bin/activate
176+
python="$HOME/.bittensor/venv/bin/python"
177+
169178
ohai "Installing bittensor"
179+
$python -m pip install --upgrade pip
170180
$python -m pip install -e ~/.bittensor/bittensor/
171181
$python -m pip install -U bittensor-cli
172-
exit_on_error $?
182+
exit_on_error $?
173183
deactivate
174184
}
175185

@@ -178,11 +188,12 @@ OS="$(uname)"
178188
if [[ "$OS" == "Linux" ]]; then
179189

180190
which -s apt-get
181-
if [[ $? == 0 ]] ; then
191+
if [[ $? != 0 ]] ; then
182192
abort "This linux based install requires apt-get. To run with other distros (centos, arch, etc), you will need to manually install the requirements"
183193
fi
194+
184195
echo """
185-
196+
186197
██████╗░██╗████████╗████████╗███████╗███╗░░██╗░██████╗░█████╗░██████╗░
187198
██╔══██╗██║╚══██╔══╝╚══██╔══╝██╔════╝████╗░██║██╔════╝██╔══██╗██╔══██╗
188199
██████╦╝██║░░░██║░░░░░░██║░░░█████╗░░██╔██╗██║╚█████╗░██║░░██║██████╔╝
@@ -260,7 +271,7 @@ fi
260271

261272
# Use the shell's audible bell.
262273
if [[ -t 1 ]]; then
263-
printf "\a"
274+
printf "\a"
264275
fi
265276

266277
echo ""
@@ -289,12 +300,12 @@ echo " $ btcli w new_hotkey"
289300
echo " $ btcli w list"
290301
echo " $ btcli s register"
291302
echo ""
303+
echo "- Check Bittensor SDK version"
304+
echo " $ python -m bittensor"
305+
echo ""
292306
echo "- Use the Python API"
293307
echo " $ python3"echo " >> import bittensor"
294308
echo ""
295-
echo "- Join the discussion: "
309+
echo "- Join the discussion:"
296310
echo " ${tty_underline}https://discord.gg/3rUr6EcvbB${tty_reset}"
297311
echo ""
298-
299-
300-

0 commit comments

Comments
 (0)