aboutsummaryrefslogtreecommitdiffhomepage
path: root/util
diff options
context:
space:
mode:
authorGravatar Olivia Nordquist <nolivia@google.com>2016-08-09 11:16:44 -0800
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2016-08-09 12:31:47 -0700
commit4959a1291045674a23793212cfe94d4804760f01 (patch)
treedbc2e389db09c077abadd961444ee04ed8309656 /util
parenta8c58014ee62b48e31a7bb627924a92fa8ff6258 (diff)
fixes github issue #2703 by asking user for a specific python path from a list of possible known locations
Change: 129778433
Diffstat (limited to 'util')
-rwxr-xr-xutil/python/python_config.sh66
1 files changed, 62 insertions, 4 deletions
diff --git a/util/python/python_config.sh b/util/python/python_config.sh
index aaad084f69..dc55da3ee6 100755
--- a/util/python/python_config.sh
+++ b/util/python/python_config.sh
@@ -45,6 +45,48 @@ function main {
esac
}
+function python_path {
+ python - <<END
+from __future__ import print_function
+import site
+import os
+
+try:
+ input = raw_input
+except NameError:
+ pass
+
+python_paths = []
+if os.getenv('PYTHONPATH') is not None:
+ python_paths = os.getenv('PYTHONPATH').split(':')
+
+all_paths = set(python_paths + site.getsitepackages())
+
+paths = []
+for path in all_paths:
+ if os.path.isdir(path):
+ paths.append(path)
+
+if len(paths) == 1:
+ print(paths[0])
+ret_paths = ""
+for path in paths:
+ ret_paths += path + " "
+print(ret_paths)
+END
+}
+
+function default_python_path {
+ PYTHON_ARG="$1" python - <<END
+from __future__ import print_function
+import os
+
+default = os.getenv('PYTHON_ARG')
+default = str(default)
+print(default)
+END
+}
+
function setup_python {
PYTHON_BIN_PATH="$1";
@@ -68,11 +110,27 @@ function setup_python {
echo -e "\n\nERROR: Problem getting python include path. Is distutils installed?"
exit 1
fi
- local python_lib=$("${PYTHON_BIN_PATH}" -c 'from __future__ import print_function; from distutils import sysconfig; print(sysconfig.get_python_lib());')
- if [ "$python_lib" == "" ]; then
- echo -e "\n\nERROR: Problem getting python lib path. Is distutils installed?"
- exit 1
+
+ local python_lib_path=$(python_path)
+ echo "Found possible Python library paths:"
+ for x in $python_lib_path; do
+ echo " $x"
+ done
+ set -- $python_lib_path
+ echo "Please input the desired Python library path to use. Default is ["$1"]"
+ read b
+ if [ "$b" == "" ]; then
+ python_lib="$(default_python_path $python_lib_path)"
+ echo $python_lib
+ else
+ if test -d $b -a -x $b; then
+ python_lib=$b
+ else
+ echo -e "\n\nERROR: The path you have entered does not exist."
+ exit 1
+ fi
fi
+
local numpy_include=$("${PYTHON_BIN_PATH}" -c 'from __future__ import print_function; import numpy; print(numpy.get_include());')
if [ "$numpy_include" == "" ]; then
echo -e "\n\nERROR: Problem getting numpy include path. Is numpy installed?"