What is python's site-packages directory?

后端 未结 3 1637
滥情空心
滥情空心 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 06:16

    site-packages is the target directory of manually built Python packages. When you build and install Python packages from source (using distutils, probably by executing python setup.py install), you will find the installed modules in site-packages by default.

    There are standard locations:

    • Unix (pure)1: prefix/lib/pythonX.Y/site-packages
    • Unix (non-pure): exec-prefix/lib/pythonX.Y/site-packages
    • Windows: prefix\Lib\site-packages

    1 Pure means that the module uses only Python code. Non-pure can contain C/C++ code as well.

    site-packages is by default part of the Python search path, so modules installed there can be imported easily afterwards.


    Useful reading

    • Installing Python Modules (for Python 2)
    • Installing Python Modules (for Python 3)

提交回复
热议问题