After installation, I would like to make soft-links to some of the configuration & data files created by installation.
How can I determine the location of a new package's files installed from within the package's setup.py?
I initially hard-coded the path "/usr/local/lib/python2.7/dist-packages", but that broke when I tried using a virtual environment. (Created by virtualenv.)
I tried distutils.sysconfig.get_python_lib(), and that works inside the virtualenv. When installed on the real system, however, it returns "/usr/lib/python2.7/dist-packages" (Note the "local" directory isn't present.)
I've also tried site.getsitepackages():
Running a Python shell from the base environment:




import site








site.getusersitepackages()





'/home/sarah/.local/lib/python2.7/site-packages'





site.getsitepackages()





['/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages']

Running a Python shell from a virtual environment "testenv":




import site








site.getsitepackages()





Traceback (most recent call last):


File "", line 1, in 


AttributeError: 'module' object has no attribute 'getsitepackages'

I'm running "Python 2.7.3 (default, Aug  1 2012, 05:14:39)" with "[GCC 4.6.3] on linux2" on Ubuntu. I can probably cobble something together with try-except blocks, but it seems like there should be some variable set / returned by distutils / setuptools. (I'm agnostic about which branch to use, as long as it works.)
Thanks.
This will probably not answer your question, but if you need to access the source code of a package you have installed, or any other file within this package, the best way to do it is to install this package in develop mode (by downloading the sources, putting it wherever you want and then running python setup.py develop in the base directory of the package sources). This way you know where the package is found.
Detect python package installation path from within setup.py