What is python's site-packages directory?

后端 未结 3 1639
滥情空心
滥情空心 2020-12-04 05:42

The directory site-packages is mentioned in various Python related articles. What is it? How to use it?

3条回答
  •  眼角桃花
    2020-12-04 05:49

    site-packages is just the location where Python installs its modules.

    No need to "find it", python knows where to find it by itself, this location is always part of the PYTHONPATH (sys.path).

    Programmatically you can find it this way:

    import sys
    site_packages = next(p for p in sys.path if 'site-packages' in p)
    print site_packages
    

    '/Users/foo/.envs/env1/lib/python2.7/site-packages'

提交回复
热议问题