I know that after installing Python via Homebrew my include directory is here:
/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/include/python2.7
Is there a way I can make Python tell me where its include/lib directories are? Something along the lines of:
python -c "import sys; print '\n'.join(sys.path)"
When a package is installed globally, it's made available to all users that log into the system. Typically, that means Python and all packages will get installed to a directory under /usr/local/bin/ for a Unix-based system, or \Program Files\ for Windows.
Clicking on the Environment Variables button on the bottom right. In the System variables section, selecting the Path variable and clicking on Edit. The next screen will show all the directories that are currently a part of the PATH variable. Clicking on New and entering Python's install directory.
There must be an easier way to do this from Python, I thought, and there is, in the standard library of course. Use get_paths
from sysconfig
:
from sysconfig import get_paths
from pprint import pprint
info = get_paths() # a dictionary of key-paths
# pretty print it for now
pprint(info)
{'data': '/usr/local',
'include': '/usr/local/include/python2.7',
'platinclude': '/usr/local/include/python2.7',
'platlib': '/usr/local/lib/python2.7/dist-packages',
'platstdlib': '/usr/lib/python2.7',
'purelib': '/usr/local/lib/python2.7/dist-packages',
'scripts': '/usr/local/bin',
'stdlib': '/usr/lib/python2.7'}
You could also use the -m
switch with sysconfig
to get the full output of all configuration values.
This should be OS/Python version agnostic, use it anywhere. :-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With