Question

I'm installing a console command using the entry_point dict in setup.py. This creates a python file in some path in the system (for example, as root in debian is /usr/local/bin) that can change depending the system or if you use virtualenvs.

I need the default path of scripts installed as entry_points with setup.py

Was it helpful?

Solution

The location can vary depending on various arguments to setup.py, including --home, --user, --prefix, --install-scripts and so on.

If the script already exists, the best way to find it would be to scan over the contents in $PATH, looking for an executable file (like the which command), but this might not be what you're after

The distutils.sysconfig module might be more helpful.

$ export WORKON_HOME='/tmp/so'
$ mkvirtualenv blah
$ python
Python 2.7.2
>>> import os
>>> import distutils.sysconfig
>>> pre = distutils.sysconfig.get_config_var("prefix")
>>> bindir = os.path.join(pre, "bin")
>>> print bindir
/tmp/so/blah/bin

..which is the directory where, for example pyflakes ends up if I run pip install pyflakes

The get_config_vars dict might be useful if you need to find a more specific location:

>>> [(k, v) for (k, v) in distutils.sysconfig.get_config_vars().items() if "/tmp/so" in str(v)]
[('prefix', '/private/tmp/so/blah'), ('exec_prefix', '/private/tmp/so/blah')]

You can more conveniently access some of these variables via the sys module, including sys.prefix and sys.execprefix

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top