Cross-platform way to get default directory for binary files like console scripts?

Oscar Benjamin oscar.j.benjamin at
Thu Feb 20 16:22:53 CET 2014

On 20 February 2014 14:27, Piotr Dobrogost
<p at> wrote:
> 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

I'm not sure if I understand the question. Are you trying to find
where a script would go if it had been installed as a result of
'python install' or 'pip install ...'? If so there are
different places it could go depending not only on the system but also
how the packages were installed (e.g. --user).

You can find the default location in this roundabout way:

In [1]: from distutils.command.install import install

In [2]: from distutils.dist import Distribution

In [3]: c = install(Distribution())

In [4]: c.finalize_
c.finalize_options  c.finalize_other    c.finalize_unix

In [4]: c.finalize_options()

In [5]: c.insta
c.install_base       c.install_headers    c.install_lib
c.install_path_file  c.install_platlib    c.install_scripts
c.install_data       c.install_layout     c.install_libbase
c.install_platbase   c.install_purelib    c.install_userbase

In [5]: c.install_scripts
Out[5]: '/usr/local/bin'


More information about the Python-list mailing list