Cross-platform way to get default directory for binary files like console scripts?
ned at nedbatchelder.com
Thu Feb 20 16:42:54 CET 2014
On 2/20/14 10:34 AM, Piotr Dobrogost wrote:
> On Thursday, February 20, 2014 4:22:53 PM UTC+1, Oscar Benjamin wrote:
>> 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 setup.py 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 : c.install_scripts
>> Out: '/usr/local/bin'
> I think this is pretty much what I'm after, thanks.
> I'm wondering if there's some API to get this info as what you showed is really roundabout way to achieve the goal...
As roundabout and advanced as that code is, it doesn't give the right
answer for me. It returns None. On my Mac, after activating a virtualenv:
Python 2.7.2 (default, Oct 11 2012, 20:14:37)
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)]
Type "help", "copyright", "credits" or "license" for more information.
>>> from distutils.command.install import install
>>> from distutils.dist import Distribution
>>> c = install(Distribution())
>>> c.install_scripts is None
['activate', 'activate.csh', 'activate.fish', 'activate_this.py',
'easy_install', 'easy_install-2.7', 'pip', 'pip-2.7', 'python',
Ned Batchelder, http://nedbatchelder.com
More information about the Python-list