Skip to content

Commit 8ad898c

Browse files
psmitdanpovey
authored andcommitted
[build] dependency-check: that python2.7 and python3 exist and 2.7 is default (#1876)
1 parent 26e8b56 commit 8ad898c

File tree

1 file changed

+34
-18
lines changed

1 file changed

+34
-18
lines changed

tools/extras/check_dependencies.sh

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -87,28 +87,44 @@ if ! which awk >&/dev/null; then
8787
add_packages gawk gawk gawk
8888
fi
8989

90-
if which python >&/dev/null ; then
90+
pythonok=true
91+
if ! which python2.7 >&/dev/null; then
92+
echo "$0: python2.7 is not installed"
93+
add_packages python2.7
94+
pythonok=false
95+
fi
96+
97+
if ! which python3 >&/dev/null; then
98+
echo "$0: python3 is not installed"
99+
add_packages python3
100+
pythonok=false
101+
fi
102+
103+
(
104+
#Use a subshell so that sourcing env.sh does not have an influence on the rest of the script
105+
[ -f ./env.sh ] && . ./env.sh
106+
if $pythonok && ! which python2 >&/dev/null; then
107+
mkdir -p $PWD/python
108+
echo "$0: python2.7 is installed, but the python2 binary does not exist. Creating a symlink and adding this to tools/env.sh"
109+
ln -s $(which python2.7) $PWD/python/python2
110+
echo "export PATH=$PWD/python:\${PATH}" >> env.sh
111+
fi
112+
113+
if [[ -f $PWD/python/.use_default_python && -f $PWD/python/python ]]; then
114+
rm $PWD/python/python
115+
fi
116+
117+
if $pythonok && which python >&/dev/null && [[ ! -f $PWD/python/.use_default_python ]]; then
91118
version=`python 2>&1 --version | awk '{print $2}' `
92119
if [[ $version != "2.7"* ]] ; then
93-
if which python2.7 >&/dev/null || which python2 >&/dev/null ; then
94-
echo "$0: python 2.7 is not the default python. You should either make it"
95-
echo "$0: default or create an bash alias for kaldi scripts to run correctly"
96-
status=1
97-
else
98-
echo "$0: python 2.7 is not installed"
99-
add_packages python2.7 python python2.7
100-
fi
101-
fi
102-
else
103-
if which python2.7 >&/dev/null || which python2 >&/dev/null ; then
104-
echo "$0: python 2.7 is not the default python. You should either make it"
105-
echo "$0: default or create an bash alias for kaldi scripts to run correctly"
106-
status=1
107-
else
108-
echo "$0: python is not installed (we need python 2.7)"
109-
add_packages python2.7 python python2.7
120+
echo "$0: WARNING python 2.7 is not the default python. We fixed this by adding a correct symlink more prominently on the path."
121+
echo "$0: If you really want to use python $version as default, add an empty file $PWD/python/.use_default_python and run this script again."
122+
mkdir -p $PWD/python
123+
ln -s $(which python2.7) $PWD/python/python
124+
echo "export PATH=$PWD/python:\${PATH}" >> env.sh
110125
fi
111126
fi
127+
)
112128

113129
printed=false
114130

0 commit comments

Comments
 (0)