linkedin / shiv

shiv is a command line utility for building fully self contained Python zipapps as outlined in PEP 441, but with all their dependencies included.
BSD 2-Clause "Simplified" License
1.75k stars 99 forks source link

support for packages with a .pth file #223

Open sdementen opened 2 years ago

sdementen commented 2 years ago

When creating a pyz file with dependencies "requests pip_system_certs", the file "pip_system_certs.pth" extracted in the ~/.shiv/pyzfolder/site-packages is not handled (tested by running import requests; requests.get("https://some.website.needing.system.certificate.store") which triggers a '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1129)' error)

Would it be possible to make the ~/.shiv/pyzfolder/site-packages folder be considered as one of the directory with .pth that are handled ?

Or automatically run the following code (will handle the .pth files in the folder) during the bootstrap ?

import site
site.addsitedir("~/.shiv/pyzfolder/site-packages")
site.main()
sdementen commented 2 years ago

Another option would be to set https://docs.python.org/3/using/cmdline.html#envvar-PYTHONUSERBASE to the uncompressed folder in .shiv but this would require to rename somewhat the uncompressed folder to make it work (eg on windows, the folder should be named ~/.shiv/name-of-folder/Python310/site-packages (instead of ~/.shiv/name-of-folder/site-packages and PYTHONUSERBASE should be set to ~/.shiv/name-of-folder.

lorencarvalho commented 2 years ago

Hi @sdementen,

PYZ files created by shiv should already be respecting .pth files, as we use site.addsitedir to evaluate the custom site-packages directory: https://github.com/linkedin/shiv/blob/4d273b2ccbb929cc865feea78978ebf0daa9f032/src/shiv/bootstrap/__init__.py#L211-L213

sdementen commented 2 years ago

Great! But it was not working on my side. Does it work for you? I wonder if we are not missing a call to site.main() after adding the path