How do I find the location of my Python site-packages directory?

前端 未结 21 2991
梦谈多话
梦谈多话 2020-11-22 03:06

How do I find the location of my site-packages directory?

21条回答
  •  粉色の甜心
    2020-11-22 03:31

    The native system packages installed with python installation in Debian based systems can be found at :

    /usr/lib/python2.7/dist-packages/

    In OSX - /Library/Python/2.7/site-packages

    by using this small code :

    from distutils.sysconfig import get_python_lib
    print get_python_lib()
    

    However, the list of packages installed via pip can be found at :

    /usr/local/bin/

    Or one can simply write the following command to list all paths where python packages are.

    >>> import site; site.getsitepackages()
    ['/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages']
    

    Note: the location might vary based on your OS, like in OSX

    >>> import site; site.getsitepackages()
    ['/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/site-python', '/Library/Python/2.7/site-packages']
    

提交回复
热议问题