On 2/20/14 9:27 AM, Piotr Dobrogost wrote:
Hi!
Is there cross-platform way to get default directory for binary files (console
scripts for instance) the same way one can use sys.executable to get path to
the Python's interpreter in cross-platform way?
Context:
There's Python script which runs various tools like pip using subprocess and we
would like to make sure we run tools that accompany Python's interpreter used
to run this script. Please note that the script may be run from within
virtualenv which had not been activated - ./venv/bin/python our_script.py
Regards,
Piotr Dobrogost
Hi Piotr, we talked about this briefly in #python this morning. I still
don't quite understand why you are averse to activating the virtualenv.
It is designed to solve precisely this problem: create an environment
that uses the natural OS tools (including PATH) to produce a consistent
environment that works the way tools expect.
If you don't activate the virtualenv, then you can look for your Python
executable using sys.executable, and see if the file you want to run is
in that same directory. I have no idea under what conditions that is
the right or wrong answer, and I don't know what to do if the file
you're looking for isn't in that directory.
Perhaps the shorter answer is, look in the Python executable directory,
then look in the directories on PATH.
--
Ned Batchelder, http://nedbatchelder.com
--
https://mail.python.org/mailman/listinfo/python-list