[Python] What is the file structure for a python project when a package is installed?

Discussão em 'Python' iniciado por Stack, Agosto 22, 2025.

  1. Stack

    Stack Membro Participativo

    Can you help me understand if, for the most part, Python package managers follow the same file structure when installing a package? For example, when dep_1 is installed, we can expect the following files and directories are created under site_packages directory:

    • sample-project
    • lib
    • python3
    • site-packages
      • dep_1-2.25.1.dist-info
      • dep_1
      • __init__.py

    I've tried this installation for pip and wondering if this is something we can expect for all python package managers?

    I've also tried running pip install google_cloud_bigquery and discovered that there are namespace package which are sometimes used for Python ver 3 and above. The file structure then became:

    • sample-project
    • lib
    • python3
    • site-packages
      • dep_1-2.25.1.dist-info
      • namespace-package-for-dep_1
        • dep_1
          • __init__.py

    In our google_cloud_bigquery example, /site_packages/google_cloud_bigquery-version.dist-info/top_level.txt file that tells me the namespace package is google. But from What is top_level.txt and when is it created?, we cannot expect this file reliably. So then, my 2nd question is how else can I reliably find where to retrieve the namespace package?

    Continue reading...

Compartilhe esta Página