6 target="${dir}/python_modules"
20 target="${dir}/python_modules"
21 echo >&2 "Will install python modules in: '${target}'"
27 echo >&2 "Will install python modules system-wide"
32 echo "${0} [--dir netdata-python.d-path] [--system]"
33 echo "Please make sure you have installed packages: python-pip (or python3-pip) python-dev libyaml-dev libmysqlclient-dev"
38 echo >&2 "Cannot understand parameter: ${1}"
45 if [ ! -z "${target}" -a ! -d "${target}" ]
47 echo >&2 "Cannot find directory: '${target}'"
51 if [[ "${pv}" =~ ^Python\ 2.* ]]
54 pip="$(which pip2 2>/dev/null)"
55 elif [[ "${pv}" =~ ^Python\ 3.* ]]
58 pip="$(which pip3 2>/dev/null)"
60 echo >&2 "Cannot detect python version. Is python installed?"
64 [ -z "${pip}" ] && pip="$(which pip 2>/dev/null)"
67 echo >&2 "pip command is required to install python v${pv} modules."
68 [ "${pv}" = "2" ] && echo >&2 "Please install python-pip."
69 [ "${pv}" = "3" ] && echo >&2 "Please install python3-pip."
73 echo >&2 "Working for python version ${pv} (pip command: '${pip}')"
74 echo >&2 "Installing netdata python modules in: '${target}'"
77 printf "Running command:\n# "
83 # try to install all the python modules given as parameters
84 # until the first that succeeds
89 local ret x msg="${1}"
94 echo >&2 "Installing one of: ${*}"
99 echo >&2 "attempting to install: ${x}"
100 if [ ! -z "${target}" ]
102 run "${pip}" install --target "${target}" "${x}"
105 run "${pip}" install "${x}"
108 [ ${ret} -eq 0 ] && break
109 echo >&2 "failed to install: ${x}. ${msg}"
116 echo >&2 "FAILED: could not install any of: ${*}. ${msg}"
119 errors=$(( errors + 1 ))
120 failed="${failed}|${*}"
124 echo >&2 "SUCCESS: we have: ${x}"
127 installed="${installed} ${x}"
134 pip_install "is libyaml-dev and python-dev installed?" pyyaml
135 pip_install "is libmysqlclient-dev and python-dev installed?" mysqlclient mysql-python pymysql
137 pip_install "is libyaml-dev and python-dev installed?" pyyaml
138 pip_install "is libmysqlclient-dev and python-dev installed?" mysql-python mysqlclient pymysql
143 if [ ${errors} -ne 0 ]
145 echo >&2 "Failed to install ${errors} modules: ${failed}"
146 if [ ! -z "${target}" ]
149 echo >&2 "If you are getting errors during cleanup from pip, there is a known bug"
150 echo >&2 "in certain versions of pip that prevents installing packages local to an"
151 echo >&2 "application. To install them system-wide please run:"
152 echo >&2 "$0 --system"
156 echo >&2 "All done. We have: ${installed}"