Is it somehow possible to programatically get the bin
/ Scripts
directory path related to the current runtime environment? It's typically /usr/lib/pythonX.Y/bin
(or C:\\PythonXY\\Scripts
), but it can be different in eg virtual environments.
I'm aware of the constants in distutils.command.install
, but I hope there is an easier way to get the path.
the virtual environment path is stored in the $VIRTUAL_ENV environment variable.
$VIRTUAL_ENV/bin/Scripts
will give you what you want if you have a virtual environment loaded. you can check to see if that virtual environment is set, and if not, fall back on the system runtime directory:
if [ -z "$VARIABLE" ]
then
dir=$VIRTUAL_ENV/bin/Scripts
else
dir=/usr/lib/pythonX.Y/bin/Scripts
fi
another thing you can try is to extrapolate the runtime directory from the output of the command 'which python', which would give you something like this:
$(which python | cut -d "'" -f 3 | sed 's/python$//')"Scripts"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.