pythonpython-wheel

Identify the full path to xxx/library/bin in python


I have an application that depends on intel-fortran-rt

When installed via pip install intel-fortran-rt==2021.3.0, the intel fortran runtime dlls are copied into xxx\Library\bin

The problem is to identify xxx across different python versions, distributions and platforms.

How does pip know where to put the files (I assume it is specified in a meta file, but could not find it) and how can I obtain the path from python


Solution

  • I assume it is specified in a meta file

    It's not. Python knows its directories. pip runs under a python and asks that python for the directories. Like this:

    $ python -c "import sys; print(sys.base_prefix); print(sys.prefix)"
    /home/phd/.local
    /home/phd/.virtualenvs/tmp-4cbd5ccc42cbf86
    

    It's a temporary virtual environment. Base directory means python is in /home/phd/.local/bin/, exact Python is

    $ python -c "import sys; print(sys.executable)"
    /home/phd/.virtualenvs/tmp-4cbd5ccc42cbf86/bin/python
    

    It's a symlink:

    $ ls -l /home/phd/.virtualenvs/tmp-4cbd5ccc42cbf86/bin/python
    lrwxrwxrwx 1 phd phd 30 Oct 22 15:26 /home/phd/.virtualenvs/tmp-4cbd5ccc42cbf86/bin/python -> /home/phd/.local/bin/python3.7
    

    The directories where Python is looking up modules and packages are:

    $ python -m site
    sys.path = [
        '/home/phd/.virtualenvs/tmp-4cbd5ccc42cbf86',
        '/home/phd/.local/lib/python37.zip',
        '/home/phd/.local/lib/python3.7',
        '/home/phd/.local/lib/python3.7/lib-dynload',
        '/home/phd/.virtualenvs/tmp-4cbd5ccc42cbf86/lib/python3.7/site-packages',
    ]
    USER_BASE: '/home/phd/.local' (exists)
    USER_SITE: '/home/phd/.local/lib/python3.7/site-packages' (exists)
    ENABLE_USER_SITE: False