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

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

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

21条回答
  •  梦如初夏
    2020-11-22 03:21

    This works for me. It will get you both dist-packages and site-packages folders. If the folder is not on Python's path, it won't be doing you much good anyway.

    import sys; 
    print [f for f in sys.path if f.endswith('packages')]
    

    Output (Ubuntu installation):

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

提交回复
热议问题