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

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

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

相关标签:
21条回答
  • 2020-11-22 03:39

    Let's say you have installed the package 'django'. import it and type in dir(django). It will show you, all the functions and attributes with that module. Type in the python interpreter -

    >>> import django
    >>> dir(django)
    ['VERSION', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__', 'get_version']
    >>> print django.__path__
    ['/Library/Python/2.6/site-packages/django']
    

    You can do the same thing if you have installed mercurial.

    This is for Snow Leopard. But I think it should work in general as well.

    0 讨论(0)
  • 2020-11-22 03:39

    An additional note to the get_python_lib function mentioned already: on some platforms different directories are used for platform specific modules (eg: modules that require compilation). If you pass plat_specific=True to the function you get the site packages for platform specific packages.

    0 讨论(0)
  • 2020-11-22 03:43

    A solution that:

    • outside of virtualenv - provides the path of global site-packages,
    • insidue a virtualenv - provides the virtualenv's site-packages

    ...is this one-liner:

    python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())"
    

    Formatted for readability (rather than use as a one-liner), that looks like the following:

    from distutils.sysconfig import get_python_lib
    print(get_python_lib())
    


    Source: an very old version of "How to Install Django" documentation (though this is useful to more than just Django installation)

    0 讨论(0)
提交回复
热议问题