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

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

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

21条回答
  •  深忆病人
    2020-11-22 03:33

    This should work on all distributions in and out of virtual environment due to it's "low-tech" nature. The os module always resides in the parent directory of 'site-packages'

    import os; print(os.path.dirname(os.__file__) + '/site-packages')
    

    To change dir to the site-packages dir I use the following alias (on *nix systems):

    alias cdsp='cd $(python -c "import os; print(os.path.dirname(os.__file__))"); cd site-packages'
    

提交回复
热议问题