Closed frickerj closed 10 months ago
You pretty much answered your own question here!
I'm wondering if this if hasattr(http.client, 'HTTPSConnection'): may return false, and thus I'm not able to import the HTTPSHandler.
Exactly. Search for HTTPSHandler here: https://docs.python.org/3.11/library/urllib.request.html
You find:
If the Python installation has SSL support (i.e., if the ssl module can be imported), HTTPSHandler will also be added.
Which links to: https://docs.python.org/3.11/library/ssl.html#module-ssl
This module provides access to Transport Layer Security (often known as “Secure Sockets Layer”) encryption and peer authentication facilities for network sockets, both client-side and server-side. This module uses the OpenSSL library. It is available on all modern Unix systems, Windows, macOS, and probably additional platforms, as long as OpenSSL is installed on that platform.
That seems to suggest you do not have OpenSSL (at least of the right version) installed.
You're on your own debugging this, but I'd suggest cutting out all middlemen and just replacing the Pants action stuff with a simple run step like so:
name: Sanity check Python 3.11 install
run: |
python3.11 -c "import url"
python3.11 -c "from urllib.request import HTTPSHandler"
Since the action you use to install Python is opaque here (I couldn't find it publicly anyhow), I can only suggest the result of an obvious search on issues importing ssl for Debian Python 3.11: https://github.com/pyenv/pyenv/issues/2760
(IOW: you may not be using pyenv at all behind the scenes and you're definitely not using an rpm based distro, but the issue details some OpenSSL version restrictions CPython 3.11 has)
I've re-labelled this to a question since it seems to be a question about how to install CPython 3.11 with ssl support.
One more homework helper: https://peps.python.org/pep-0644/
Thanks for your huge help on this @jsirois, really appreciate it!
I've added this step to my action, per your message
- name: Sanity check Python 3.11 install
run: |
python3.11 -c 'from urllib.request import HTTPSHandler; print("hello")'
Surprisingly, this step passes, while the error highlighted in the original post continues to occur when pex is trying to find an interpreter.
Step logs
Run python3.11 -c 'from urllib.request import HTTPSHandler; print("hello")'
python3.11 -c 'from urllib.request import HTTPSHandler; print("hello")'
shell: /usr/bin/bash -e {0}
env:
pythonLocation: /actions-runner/install/_work/_tool/Python/3.11.7/x64
PKG_CONFIG_PATH: /actions-runner/install/_work/_tool/Python/3.11.7/x64/lib/pkgconfig
Python_ROOT_DIR: /actions-runner/install/_work/_tool/Python/3.11.7/x64
Python2_ROOT_DIR: /actions-runner/install/_work/_tool/Python/3.11.7/x64
Python3_ROOT_DIR: /actions-runner/install/_work/_tool/Python/3.11.7/x64
LD_LIBRARY_PATH: /actions-runner/install/_work/_tool/Python/3.11.7/x64/lib
hello
This also works: python3.11 -c 'from urllib.request import HTTPSHandler; import ssl; print( ssl.__file__ ); print("hello")'
I'm not exactly sure why this would happen, I'll continue to dig but it seems like the issue might be with pex?
I'm not exactly sure why this would happen, I'll continue to dig but it seems like the issue might be with pex?
That still seems highly unlikely.
So ... debugging 101, and I'm guilty of a sloppy rec here, using things like python3.11
is imprecise. Again, your action to install Python is opaque to me, but you suspiciously sudo apt-get update && sudo apt-get install -y libpython3.11-dev ...
above which implies the debian-based distro you use carries it own Python 3.11 in addition to whatever is in /actions-runner/install/_work/_tool/Python/3.11.7/x64
. Have you tried which -a python3.11
to see if there are multiple Python 3.11's on the machine? Your OP error shows Pex has a problem with /actions-runner/install/_work/_tool/Python/3.11.7/x64/bin/python3.11
- to confirm your debugging run step is testing the same interpreter you might use that absolute path.
I'm able to reproduce this error removing all apt-get, except this
- name: install libpython3.11-dev
run: sudo apt-get update && sudo apt-get install -y libpython3.11-dev
Without this step, I get this error:
Skipped the following broken interpreters:
1.) /actions-runner/install/_work/_tool/Python/3.11.7/x64/bin/python3.11:
/actions-runner/install/_work/_tool/Python/3.11.7/x64/bin/python3.11: error while loading shared libraries: libpython3.11.so.1.0: cannot open shared object file: No such file or directory
This error surprises me because the file does exist, and is in the LD_LIBRARY_PATH
.
I've confirmed via which -a
that there is only one python3.11 installation.
Our setup-python action is just a wrapper around the github setup-python that also sets the registries to our internal mirrors.
I'm still quite confused why everything seems to work normally elsewhere but not with pants. Will continue to dig, really appreciate your help with this!
@#$! Pants: LD_LIBRARY_PATH
... Pants is hermetic by default; that means it masks almost all env vars from processes it runs. It looks like your /actions-runner/install/_work/_tool/Python/3.11.7/x64/bin/python3.11
probably relies on LD_LIBRARY_PATH=/actions-runner/install/_work/_tool/Python/3.11.7/x64/lib
being available in the environment for ld.so
to find and link ssl at Python executable boot time. You might check the contents of the /actions-runner/install/_work/_tool/Python/3.11.7/x64/lib
tree to see if it has what looks to be an open ssl .so in there to confirm my hunch, but you might also just plow ahead and configure https://www.pantsbuild.org/docs/reference-subprocess-environment#env_vars in a CI-specific pants.toml
like so:
[subprocess-environment]
env_vars.add = ["LD_LIBRARY_PATH"]
Or else in a CI-specific env var like so (see: https://www.pantsbuild.org/docs/options#environment-variables-3) : PANTS_SUBPROCESS_ENVIRONMENT=LD_LIBRARY_PATH
@frickerj I owe you a Coke, but yes - LD_LIBRARY_PATH
is, in fact, the issue. Please report back with success or failure after ensuring Pants leaks LD_LIBRARY_PATH
and we can close this as an answered question.
[subprocess-environment]
env_vars.add = ["LD_LIBRARY_PATH"]
It works! Have tried a few times now and it has worked every time. Thanks mate, I really appreciate your help!
I <3 Pants
Describe the bug A clear and concise description of the bug.
I am operating in a corporate environment, using github actions.
When trying to run pants, I get this error:
I do not expect this error to occur. I have installed
python3-distlib
per the mentioned issue here: https://github.com/pantsbuild/pex/issues/1027I have printed the content of the file (request.py), and I see this relevant section:
I'm wondering if this
if hasattr(http.client, 'HTTPSConnection'):
may return false, and thus I'm not able to import the HTTPSHandler.Pants version Which version of Pants are you using?
2.19.0rc3
OS Are you encountering the bug on MacOS, Linux, or both?
Linux, gha
Additional info Add any other information about the problem here, such as attachments or links to gists, if relevant.
Pants.toml
Github Action