>>> import distutils.sysconfig
>>> distutils.sysconfig.get_python_lib()
/usr/lib/python2.7/dist-packages
But I want this path: /usr/local/lib/python2.7/dist-packages.
I can’t use the sysconfig module because it is only supported on python2.7 and there is no PyPI download to that module. so I could not even use a requirements file to let other users download it with pip.
So, is there any way to get the path to my installed packages that works for Linux and OS X operating systems? (or even all Unix based os’s)
If you need the specific functionality of the
get_python_libfunction, the source for that module is fairly straightforward and doesn’t use any Python 2.7 specific syntax at all; you could simply backport it.You’d basically need the following definitions and two functions:
You can cut the long function down to just the branch you need for your platform, of course; for OS X that’d be:
Note that Debian patches this function to return
dist-packagesin the default case, this doesn’t apply to OS X.