Skip to content

add patch to Python 3.13.5 + 3.14.2 easyconfigs to fix ctypes when $LD_LIBRARY_PATH is not being set#25106

Merged
casparvl merged 5 commits intoeasybuilders:developfrom
bedroge:python_ctypes_patch
Jan 21, 2026
Merged

add patch to Python 3.13.5 + 3.14.2 easyconfigs to fix ctypes when $LD_LIBRARY_PATH is not being set#25106
casparvl merged 5 commits intoeasybuilders:developfrom
bedroge:python_ctypes_patch

Conversation

@bedroge
Copy link
Copy Markdown
Contributor

@bedroge bedroge commented Jan 20, 2026

See #23499, but this was left out for new Python versions.

@github-actions github-actions bot added 2025b issues & PRs related to 2025b common toolchains change labels Jan 20, 2026
@bedroge
Copy link
Copy Markdown
Contributor Author

bedroge commented Jan 20, 2026

@boegelbot please test @ jsc-zen3
EB_ARGS="--installpath=/tmp/$USER/ecpr-25106"

@boegelbot
Copy link
Copy Markdown
Collaborator

@bedroge: Request for testing this PR well received on jsczen3l1.int.jsc-zen3.fz-juelich.de

PR test command 'if [[ develop != 'develop' ]]; then EB_BRANCH=develop ./easybuild_develop.sh 2> /dev/null 1>&2; EB_PREFIX=/home/boegelbot/easybuild/develop source init_env_easybuild_develop.sh; fi; EB_PR=25106 EB_ARGS="--installpath=/tmp/$USER/ecpr-25106" EB_CONTAINER= EB_REPO=easybuild-easyconfigs EB_BRANCH=develop /opt/software/slurm/bin/sbatch --job-name test_PR_25106 --ntasks=8 ~/boegelbot/eb_from_pr_upload_jsc-zen3.sh' executed!

  • exit code: 0
  • output:
Submitted batch job 9440

Test results coming soon (I hope)...

Details

- notification for comment with ID 3772914867 processed

Message to humans: this is just bookkeeping information for me,
it is of no use to you (unless you think I have a bug, which I don't).

@casparvl
Copy link
Copy Markdown
Contributor

Test report by @casparvl
SUCCESS
Build succeeded for 1 out of 1 (total: 17 mins 31 secs) (1 easyconfigs in total)
tcn398.local.snellius.surf.nl - Linux RHEL 9.6, x86_64, AMD EPYC 7H12 64-Core Processor (zen2), Python 3.13.4
See https://gist.github.com/casparvl/e15883b609a889ad62521a5c43dba7a3 for a full test report.

@boegelbot
Copy link
Copy Markdown
Collaborator

Test report by @boegelbot
SUCCESS
Build succeeded for 2 out of 2 (total: 35 mins 3 secs) (2 easyconfigs in total)
jsczen3c1.int.jsc-zen3.fz-juelich.de - Linux Rocky Linux 9.7, x86_64, AMD EPYC-Milan Processor (zen3), Python 3.9.23
See https://gist.github.com/boegelbot/fd2d290d204f48df02b64e55981c1fa9 for a full test report.

@bedroge
Copy link
Copy Markdown
Contributor Author

bedroge commented Jan 20, 2026

@boegelbot please test @ jsc-zen3
EB_ARGS="--installpath=/tmp/$USER/ecpr-25106 --filter-env-vars=LD_LIBRARY_PATH"

@boegelbot
Copy link
Copy Markdown
Collaborator

@bedroge: Request for testing this PR well received on jsczen3l1.int.jsc-zen3.fz-juelich.de

PR test command 'if [[ develop != 'develop' ]]; then EB_BRANCH=develop ./easybuild_develop.sh 2> /dev/null 1>&2; EB_PREFIX=/home/boegelbot/easybuild/develop source init_env_easybuild_develop.sh; fi; EB_PR=25106 EB_ARGS="--installpath=/tmp/$USER/ecpr-25106 --filter-env-vars=LD_LIBRARY_PATH" EB_CONTAINER= EB_REPO=easybuild-easyconfigs EB_BRANCH=develop /opt/software/slurm/bin/sbatch --job-name test_PR_25106 --ntasks=8 ~/boegelbot/eb_from_pr_upload_jsc-zen3.sh' executed!

  • exit code: 0
  • output:
Submitted batch job 9441

Test results coming soon (I hope)...

Details

- notification for comment with ID 3773201401 processed

Message to humans: this is just bookkeeping information for me,
it is of no use to you (unless you think I have a bug, which I don't).

@boegelbot
Copy link
Copy Markdown
Collaborator

Test report by @boegelbot
FAILED
Build succeeded for 1 out of 2 (total: 16 mins 30 secs) (2 easyconfigs in total)
jsczen3c1.int.jsc-zen3.fz-juelich.de - Linux Rocky Linux 9.7, x86_64, AMD EPYC-Milan Processor (zen3), Python 3.9.23
See https://gist.github.com/boegelbot/0e8271f82909b6ff2e8b18234174a313 for a full test report.

@bedroge
Copy link
Copy Markdown
Contributor Author

bedroge commented Jan 20, 2026

Need to update the patch for 3.14.

@bedroge
Copy link
Copy Markdown
Contributor Author

bedroge commented Jan 20, 2026

@boegelbot please test @ jsc-zen3
EB_ARGS="--installpath=/tmp/$USER/ecpr-25106 --filter-env-vars=LD_LIBRARY_PATH"

@boegelbot
Copy link
Copy Markdown
Collaborator

@bedroge: Request for testing this PR well received on jsczen3l1.int.jsc-zen3.fz-juelich.de

PR test command 'if [[ develop != 'develop' ]]; then EB_BRANCH=develop ./easybuild_develop.sh 2> /dev/null 1>&2; EB_PREFIX=/home/boegelbot/easybuild/develop source init_env_easybuild_develop.sh; fi; EB_PR=25106 EB_ARGS="--installpath=/tmp/$USER/ecpr-25106 --filter-env-vars=LD_LIBRARY_PATH" EB_CONTAINER= EB_REPO=easybuild-easyconfigs EB_BRANCH=develop /opt/software/slurm/bin/sbatch --job-name test_PR_25106 --ntasks=8 ~/boegelbot/eb_from_pr_upload_jsc-zen3.sh' executed!

  • exit code: 0
  • output:
Submitted batch job 9444

Test results coming soon (I hope)...

Details

- notification for comment with ID 3773562209 processed

Message to humans: this is just bookkeeping information for me,
it is of no use to you (unless you think I have a bug, which I don't).

@Thyre Thyre added the 2026.1 issues & PRs related to 2026.1 common toolchains label Jan 20, 2026
@boegelbot
Copy link
Copy Markdown
Collaborator

Test report by @boegelbot
FAILED
Build succeeded for 1 out of 2 (total: 27 mins 28 secs) (2 easyconfigs in total)
jsczen3c1.int.jsc-zen3.fz-juelich.de - Linux Rocky Linux 9.7, x86_64, AMD EPYC-Milan Processor (zen3), Python 3.9.23
See https://gist.github.com/boegelbot/9a6900895e5ea215416af195382dc6b1 for a full test report.

@boegel boegel changed the title add patch to Python 3.13.5 + 3.14.2 easyconfigs to fix ctypes when $LD_LIBRARY_PATH is not being set add patch to Python 3.13.5 + 3.14.2 easyconfigs to fix ctypes when $LD_LIBRARY_PATH is not being set Jan 20, 2026
@boegel boegel added this to the next release (5.2.1?) milestone Jan 20, 2026
@boegel boegel added the EESSI Related to EESSI project label Jan 20, 2026
@boegel
Copy link
Copy Markdown
Member

boegel commented Jan 20, 2026

@casparvl Still needs some love?

@bedroge
Copy link
Copy Markdown
Contributor Author

bedroge commented Jan 21, 2026

Looks like it failed because Lib/ctypes/util.py is doing an import ctypes now in 3.14.2, and our patch adds a from ctypes.util import find_library, causing a circular import. I've fixed that in 9cd5dc4 by making this a lazy import (by moving the import to the relevant piece of code).

@bedroge
Copy link
Copy Markdown
Contributor Author

bedroge commented Jan 21, 2026

@boegelbot please test @ jsc-zen3
EB_ARGS="--installpath=/tmp/$USER/ecpr-25106 --filter-env-vars=LD_LIBRARY_PATH"

@boegelbot
Copy link
Copy Markdown
Collaborator

@bedroge: Request for testing this PR well received on jsczen3l1.int.jsc-zen3.fz-juelich.de

PR test command 'if [[ develop != 'develop' ]]; then EB_BRANCH=develop ./easybuild_develop.sh 2> /dev/null 1>&2; EB_PREFIX=/home/boegelbot/easybuild/develop source init_env_easybuild_develop.sh; fi; EB_PR=25106 EB_ARGS="--installpath=/tmp/$USER/ecpr-25106 --filter-env-vars=LD_LIBRARY_PATH" EB_CONTAINER= EB_REPO=easybuild-easyconfigs EB_BRANCH=develop /opt/software/slurm/bin/sbatch --job-name test_PR_25106 --ntasks=8 ~/boegelbot/eb_from_pr_upload_jsc-zen3.sh' executed!

  • exit code: 0
  • output:
Submitted batch job 9455

Test results coming soon (I hope)...

Details

- notification for comment with ID 3777123340 processed

Message to humans: this is just bookkeeping information for me,
it is of no use to you (unless you think I have a bug, which I don't).

@bedroge
Copy link
Copy Markdown
Contributor Author

bedroge commented Jan 21, 2026

Test report by @bedroge
FAILED
Build succeeded for 1 out of 2 (total: 28 mins 43 secs) (2 easyconfigs in total)
bob-Latitude-5300 - Linux Ubuntu 25.04 (Plucky Puffin), x86_64, Intel(R) Core(TM) i7-8665U CPU @ 1.90GHz, Python 3.13.3
See https://gist.github.com/bedroge/6b955bfe975517707d06d2dd8eeab32b for a full test report.

edit: this failed because I wiped the (temporary) working dir in which EB was started 😅 will try again...

@boegelbot
Copy link
Copy Markdown
Collaborator

Test report by @boegelbot
SUCCESS
Build succeeded for 2 out of 2 (total: 34 mins 21 secs) (2 easyconfigs in total)
jsczen3c1.int.jsc-zen3.fz-juelich.de - Linux Rocky Linux 9.7, x86_64, AMD EPYC-Milan Processor (zen3), Python 3.9.23
See https://gist.github.com/boegelbot/81b19c3673b769a574add36911557230 for a full test report.

@bedroge
Copy link
Copy Markdown
Contributor Author

bedroge commented Jan 21, 2026

Test report by @bedroge
SUCCESS
Build succeeded for 2 out of 2 (total: 30 mins 10 secs) (2 easyconfigs in total)
bob-Latitude-5300 - Linux Ubuntu 25.04 (Plucky Puffin), x86_64, Intel(R) Core(TM) i7-8665U CPU @ 1.90GHz, Python 3.13.3
See https://gist.github.com/bedroge/e8a32bfbb84f5393075750bf6c591eb6 for a full test report.

edit: this was without filtering $LD_LIBRARY_PATH.

@bedroge
Copy link
Copy Markdown
Contributor Author

bedroge commented Jan 21, 2026

@boegelbot please test @ jsc-zen3
EB_ARGS="--installpath=/tmp/$USER/ecpr-25106"

@boegelbot
Copy link
Copy Markdown
Collaborator

@bedroge: Request for testing this PR well received on jsczen3l1.int.jsc-zen3.fz-juelich.de

PR test command 'if [[ develop != 'develop' ]]; then EB_BRANCH=develop ./easybuild_develop.sh 2> /dev/null 1>&2; EB_PREFIX=/home/boegelbot/easybuild/develop source init_env_easybuild_develop.sh; fi; EB_PR=25106 EB_ARGS="--installpath=/tmp/$USER/ecpr-25106" EB_CONTAINER= EB_REPO=easybuild-easyconfigs EB_BRANCH=develop /opt/software/slurm/bin/sbatch --job-name test_PR_25106 --ntasks=8 ~/boegelbot/eb_from_pr_upload_jsc-zen3.sh' executed!

  • exit code: 0
  • output:
Submitted batch job 9457

Test results coming soon (I hope)...

Details

- notification for comment with ID 3777425408 processed

Message to humans: this is just bookkeeping information for me,
it is of no use to you (unless you think I have a bug, which I don't).

@bedroge
Copy link
Copy Markdown
Contributor Author

bedroge commented Jan 21, 2026

Test report by @bedroge
SUCCESS
Build succeeded for 2 out of 2 (total: 27 mins 55 secs) (2 easyconfigs in total)
bob-Latitude-5300 - Linux Ubuntu 25.04 (Plucky Puffin), x86_64, Intel(R) Core(TM) i7-8665U CPU @ 1.90GHz, Python 3.13.3
See https://gist.github.com/bedroge/123687e2ea887310f57c76c679fca144 for a full test report.

edit: this was with filtering $LD_LIBRARY_PATH.

@bedroge
Copy link
Copy Markdown
Contributor Author

bedroge commented Jan 21, 2026

Test report by @bedroge
SUCCESS
Build succeeded for 1 out of 1 (total: 12 mins 22 secs) (1 easyconfigs in total)
x86-64-amd-zen4-node1.int.aws-rocky88-202310.eessi.io - Linux Rocky Linux 8.10 (Green Obsidian), x86_64, AMD EPYC 9R14, Python 3.13.4
See https://gist.github.com/bedroge/edd795ec9eb9c4c14c7dd343e4980a61 for a full test report.

edit: this is a build on top of EESSI 2025.06 (i.e. with filtering $LD_LIBRARY_PATH).

@boegelbot
Copy link
Copy Markdown
Collaborator

Test report by @boegelbot
SUCCESS
Build succeeded for 2 out of 2 (total: 35 mins 49 secs) (2 easyconfigs in total)
jsczen3c1.int.jsc-zen3.fz-juelich.de - Linux Rocky Linux 9.7, x86_64, AMD EPYC-Milan Processor (zen3), Python 3.9.23
See https://gist.github.com/boegelbot/99aaa93f7ddf94f40651c45a6d126c7c for a full test report.

Copy link
Copy Markdown
Contributor

@casparvl casparvl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks fine to me. One final request @bedroge :

Can you run the script that I pasted in #23499 (review) on one of the patched Python installations (i.e. one done while filtering LD_LIBRARY_PATH) to test if the behavior/output is indeed as expected (i.e. identical to what was mentioned in that comment?). If it produces the expected output, I'd say this is ready to go.

@bedroge
Copy link
Copy Markdown
Contributor Author

bedroge commented Jan 21, 2026

Adapted your script a bit for my local stack (EESSI doesn't have SDL2 / CUDA yet for 2025.06, which we need for this Python version) where Python was installed with --filter-env-vars=LD_LIBRARY_PATH:

$ cat test_python_ctypes.sh 
#!/bin/bash

module purge
#module load EESSI/2025.06
#module load EESSI-extend
module load Python/3.13.5-GCCcore-14.3.0
module load SDL2/2.32.10-GCCcore-14.3.0
module load CUDA/12.9.1

# Testing find_library by library name

for lib in foo c SDL2 cuda; do
  echo "Running find_library for $lib"
  python -c "import ctypes; from ctypes.util import find_library; print(find_library('$lib'))"
  echo ""
done

# Testing library loads by full name
for lib in libfoo libSDL2.so libSDL2-2.0.so.0 libSDL2-2.0.so.0.3200.10 libc.so libc.so.6 libcuda.so; do
  echo "Instantiating CDLL object for $lib"
  python -c "import ctypes; print(ctypes.CDLL('$lib'))"
  echo "Running LoadLibrary for $lib"
  python -c "import ctypes; print(ctypes.cdll.LoadLibrary('$lib'))"
  echo "Running find_library for $lib"
  python -c "import ctypes; from ctypes.util import find_library; print(find_library('$lib'))"
  echo ""
done

# Testing library loads by full path
for lib in $EBROOTSDL2/lib64/libSDL2.so /usr/lib/x86_64-linux-gnu/libc.so.6; do
  echo "Instantiating CDLL object for $lib"
  python -c "import ctypes; print(ctypes.CDLL('$lib'))"
  echo "Running LoadLibrary for $lib"
  python -c "import ctypes; print(ctypes.cdll.LoadLibrary('$lib'))"
  echo ""
done

Running it results in:

$ ./test_python_ctypes.sh 
Running find_library for foo
None

Running find_library for c
/lib/x86_64-linux-gnu/libc.so.6

Running find_library for SDL2
/data/apps/software/SDL2/2.32.10-GCCcore-14.3.0/lib/../lib64/libSDL2.so

Running find_library for cuda
None

Instantiating CDLL object for libfoo
Traceback (most recent call last):
  File "<string>", line 1, in <module>
    import ctypes; print(ctypes.CDLL('libfoo'))
                         ~~~~~~~~~~~^^^^^^^^^^
  File "/data/apps/software/Python/3.13.5-GCCcore-14.3.0/lib/python3.13/ctypes/__init__.py", line 399, in __init__
    self._handle = _dlopen(self._name, mode)
                   ~~~~~~~^^^^^^^^^^^^^^^^^^
OSError: libfoo: cannot open shared object file: No such file or directory
Running LoadLibrary for libfoo
Traceback (most recent call last):
  File "<string>", line 1, in <module>
    import ctypes; print(ctypes.cdll.LoadLibrary('libfoo'))
                         ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
  File "/data/apps/software/Python/3.13.5-GCCcore-14.3.0/lib/python3.13/ctypes/__init__.py", line 480, in LoadLibrary
    return self._dlltype(name)
           ~~~~~~~~~~~~~^^^^^^
  File "/data/apps/software/Python/3.13.5-GCCcore-14.3.0/lib/python3.13/ctypes/__init__.py", line 399, in __init__
    self._handle = _dlopen(self._name, mode)
                   ~~~~~~~^^^^^^^^^^^^^^^^^^
OSError: libfoo: cannot open shared object file: No such file or directory
Running find_library for libfoo
None

Instantiating CDLL object for libSDL2.so
<CDLL '/data/apps/software/SDL2/2.32.10-GCCcore-14.3.0/lib/../lib64/libSDL2.so', handle 33c873a0 at 0x72fb23d370e0>
Running LoadLibrary for libSDL2.so
<CDLL '/data/apps/software/SDL2/2.32.10-GCCcore-14.3.0/lib/../lib64/libSDL2.so', handle 26f5cfb0 at 0x77ec575370e0>
Running find_library for libSDL2.so
/data/apps/software/SDL2/2.32.10-GCCcore-14.3.0/lib/../lib64/libSDL2.so

Instantiating CDLL object for libSDL2-2.0.so.0
<CDLL '/data/apps/software/SDL2/2.32.10-GCCcore-14.3.0/lib/../lib64/libSDL2-2.0.so.0', handle 234f7f0 at 0x780da87370e0>
Running LoadLibrary for libSDL2-2.0.so.0
<CDLL '/data/apps/software/SDL2/2.32.10-GCCcore-14.3.0/lib/../lib64/libSDL2-2.0.so.0', handle b108f40 at 0x76533c7370e0>
Running find_library for libSDL2-2.0.so.0
/data/apps/software/SDL2/2.32.10-GCCcore-14.3.0/lib/../lib64/libSDL2-2.0.so.0

Instantiating CDLL object for libSDL2-2.0.so.0.3200.10
<CDLL '/data/apps/software/SDL2/2.32.10-GCCcore-14.3.0/lib/../lib64/libSDL2-2.0.so.0.3200.10', handle 3d301f00 at 0x7542f9d370e0>
Running LoadLibrary for libSDL2-2.0.so.0.3200.10
<CDLL '/data/apps/software/SDL2/2.32.10-GCCcore-14.3.0/lib/../lib64/libSDL2-2.0.so.0.3200.10', handle 223d0ec0 at 0x76eb57b370e0>
Running find_library for libSDL2-2.0.so.0.3200.10
/data/apps/software/SDL2/2.32.10-GCCcore-14.3.0/lib/../lib64/libSDL2-2.0.so.0.3200.10

Instantiating CDLL object for libc.so
<CDLL '/lib/x86_64-linux-gnu/libc.so.6', handle 7d90155feec0 at 0x7d90145370e0>
Running LoadLibrary for libc.so
<CDLL '/lib/x86_64-linux-gnu/libc.so.6', handle 71360a4d5ec0 at 0x713609d370e0>
Running find_library for libc.so
/lib/x86_64-linux-gnu/libc.so.6

Instantiating CDLL object for libc.so.6
<CDLL '/lib/x86_64-linux-gnu/libc.so.6', handle 78008af3aec0 at 0x78008a7370e0>
Running LoadLibrary for libc.so.6
<CDLL '/lib/x86_64-linux-gnu/libc.so.6', handle 757f69c44ec0 at 0x757f68b370e0>
Running find_library for libc.so.6
/lib/x86_64-linux-gnu/libc.so.6

Instantiating CDLL object for libcuda.so
Traceback (most recent call last):
  File "<string>", line 1, in <module>
    import ctypes; print(ctypes.CDLL('libcuda.so'))
                         ~~~~~~~~~~~^^^^^^^^^^^^^^
  File "/data/apps/software/Python/3.13.5-GCCcore-14.3.0/lib/python3.13/ctypes/__init__.py", line 399, in __init__
    self._handle = _dlopen(self._name, mode)
                   ~~~~~~~^^^^^^^^^^^^^^^^^^
OSError: libcuda.so: cannot open shared object file: No such file or directory
Running LoadLibrary for libcuda.so
Traceback (most recent call last):
  File "<string>", line 1, in <module>
    import ctypes; print(ctypes.cdll.LoadLibrary('libcuda.so'))
                         ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
  File "/data/apps/software/Python/3.13.5-GCCcore-14.3.0/lib/python3.13/ctypes/__init__.py", line 480, in LoadLibrary
    return self._dlltype(name)
           ~~~~~~~~~~~~~^^^^^^
  File "/data/apps/software/Python/3.13.5-GCCcore-14.3.0/lib/python3.13/ctypes/__init__.py", line 399, in __init__
    self._handle = _dlopen(self._name, mode)
                   ~~~~~~~^^^^^^^^^^^^^^^^^^
OSError: libcuda.so: cannot open shared object file: No such file or directory
Running find_library for libcuda.so
None

Instantiating CDLL object for /data/apps/software/SDL2/2.32.10-GCCcore-14.3.0/lib64/libSDL2.so
<CDLL '/data/apps/software/SDL2/2.32.10-GCCcore-14.3.0/lib64/libSDL2.so', handle 25a4ed70 at 0x760bf2d370e0>
Running LoadLibrary for /data/apps/software/SDL2/2.32.10-GCCcore-14.3.0/lib64/libSDL2.so
<CDLL '/data/apps/software/SDL2/2.32.10-GCCcore-14.3.0/lib64/libSDL2.so', handle 1f017580 at 0x7756bdd370e0>

Instantiating CDLL object for /usr/lib/x86_64-linux-gnu/libc.so.6
<CDLL '/usr/lib/x86_64-linux-gnu/libc.so.6', handle 7c599243dec0 at 0x7c59913370e0>
Running LoadLibrary for /usr/lib/x86_64-linux-gnu/libc.so.6
<CDLL '/usr/lib/x86_64-linux-gnu/libc.so.6', handle 75ccae424ec0 at 0x75ccad3370e0>

Copy link
Copy Markdown
Member

@boegel boegel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, but I prefer that @casparvl takes another look at the script output that was shared by @bedroge (and merges)

@bedroge
Copy link
Copy Markdown
Contributor Author

bedroge commented Jan 21, 2026

Also ran a similar script on top of EESSI 2025.06 (without CUDA, and with a Python 3.13.5 reinstalled using EESSI-extend with the easyconfig from this PR):

$ cat test_python_ctypes_sysroot.sh
#!/bin/bash

module purge
module load EESSI/2025.06
module load EESSI-extend
module load Python/3.13.5-GCCcore-14.3.0
module load libidn2/2.3.8-GCCcore-14.3.0

# Testing find_library by library name

for lib in foo c idn2; do
  echo "Running find_library for $lib"
  python -c "import ctypes; from ctypes.util import find_library; print(find_library('$lib'))"
  echo ""
done

# Testing library loads by full name
for lib in libfoo libidn2.so  libidn2.so.0  libidn2.so.0.4.0 libc.so libc.so.6; do
  echo "Instantiating CDLL object for $lib"
  python -c "import ctypes; print(ctypes.CDLL('$lib'))"
  echo "Running LoadLibrary for $lib"
  python -c "import ctypes; print(ctypes.cdll.LoadLibrary('$lib'))"
  echo "Running find_library for $lib"
  python -c "import ctypes; from ctypes.util import find_library; print(find_library('$lib'))"
  echo ""
done

# Testing library loads by full path
for lib in $EBROOTLIBIDN2/lib64/libidn2.so ${EPREFIX}/lib64/libc.so.6; do
  echo "Instantiating CDLL object for $lib"
  python -c "import ctypes; print(ctypes.CDLL('$lib'))"
  echo "Running LoadLibrary for $lib"
  python -c "import ctypes; print(ctypes.cdll.LoadLibrary('$lib'))"
  echo ""
done

Output:

-- Using /tmp/$USER as a temporary working directory for installations, you can override this by setting the environment variable WORKING_DIR and reloading the module (e.g., /dev/shm
is a common option) 
Configuring for use of EESSI_USER_INSTALL under /home/bob/eessi
-- To create installations for EESSI, you _must_ have write permissions to /home/bob/eessi/versions/2025.06/software/linux/x86_64/intel/haswell
-- You may wish to configure a sources directory for EasyBuild (for example, via setting the environment variable EASYBUILD_SOURCEPATH) to allow you to reuse existing sources for
packages. 
Running find_library for foo
None

Running find_library for c
/cvmfs/software.eessi.io/versions/2025.06/compat/linux/x86_64/lib64/libc.so.6

Running find_library for idn2
/cvmfs/software.eessi.io/versions/2025.06/compat/linux/x86_64/usr/lib64/libidn2.so.0

Instantiating CDLL object for libfoo
Traceback (most recent call last):
  File "<string>", line 1, in <module>
    import ctypes; print(ctypes.CDLL('libfoo'))
                         ~~~~~~~~~~~^^^^^^^^^^
  File "/home/bob/eessi/versions/2025.06/software/linux/x86_64/intel/haswell/software/Python/3.13.5-GCCcore-14.3.0/lib/python3.13/ctypes/__init__.py", line 399, in __init__
    self._handle = _dlopen(self._name, mode)
                   ~~~~~~~^^^^^^^^^^^^^^^^^^
OSError: libfoo: cannot open shared object file: No such file or directory
Running LoadLibrary for libfoo
Traceback (most recent call last):
  File "<string>", line 1, in <module>
    import ctypes; print(ctypes.cdll.LoadLibrary('libfoo'))
                         ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
  File "/home/bob/eessi/versions/2025.06/software/linux/x86_64/intel/haswell/software/Python/3.13.5-GCCcore-14.3.0/lib/python3.13/ctypes/__init__.py", line 480, in LoadLibrary
    return self._dlltype(name)
           ~~~~~~~~~~~~~^^^^^^
  File "/home/bob/eessi/versions/2025.06/software/linux/x86_64/intel/haswell/software/Python/3.13.5-GCCcore-14.3.0/lib/python3.13/ctypes/__init__.py", line 399, in __init__
    self._handle = _dlopen(self._name, mode)
                   ~~~~~~~^^^^^^^^^^^^^^^^^^
OSError: libfoo: cannot open shared object file: No such file or directory
Running find_library for libfoo
None

Instantiating CDLL object for libidn2.so
<CDLL '/cvmfs/software.eessi.io/versions/2025.06/software/linux/x86_64/intel/haswell/software/libidn2/2.3.8-GCCcore-14.3.0/lib/../lib64/libidn2.so', handle 6f4d720 at 0x71ce15bab230>
Running LoadLibrary for libidn2.so
<CDLL '/cvmfs/software.eessi.io/versions/2025.06/software/linux/x86_64/intel/haswell/software/libidn2/2.3.8-GCCcore-14.3.0/lib/../lib64/libidn2.so', handle 1b471840 at 0x707eeef37230>
Running find_library for libidn2.so
/cvmfs/software.eessi.io/versions/2025.06/software/linux/x86_64/intel/haswell/software/libidn2/2.3.8-GCCcore-14.3.0/lib/../lib64/libidn2.so

Instantiating CDLL object for libidn2.so.0
<CDLL '/cvmfs/software.eessi.io/versions/2025.06/software/linux/x86_64/intel/haswell/software/libidn2/2.3.8-GCCcore-14.3.0/lib/../lib64/libidn2.so.0', handle 2203c810 at 0x78e02e737230>
Running LoadLibrary for libidn2.so.0
<CDLL '/cvmfs/software.eessi.io/versions/2025.06/software/linux/x86_64/intel/haswell/software/libidn2/2.3.8-GCCcore-14.3.0/lib/../lib64/libidn2.so.0', handle 31d44960 at 0x7694ee737230>
Running find_library for libidn2.so.0
/cvmfs/software.eessi.io/versions/2025.06/software/linux/x86_64/intel/haswell/software/libidn2/2.3.8-GCCcore-14.3.0/lib/../lib64/libidn2.so.0

Instantiating CDLL object for libidn2.so.0.4.0
<CDLL '/cvmfs/software.eessi.io/versions/2025.06/software/linux/x86_64/intel/haswell/software/libidn2/2.3.8-GCCcore-14.3.0/lib/../lib64/libidn2.so.0.4.0', handle 19280f20 at 0x785cc498f230>
Running LoadLibrary for libidn2.so.0.4.0
<CDLL '/cvmfs/software.eessi.io/versions/2025.06/software/linux/x86_64/intel/haswell/software/libidn2/2.3.8-GCCcore-14.3.0/lib/../lib64/libidn2.so.0.4.0', handle 1d288f60 at 0x71b42c17f230>
Running find_library for libidn2.so.0.4.0
/cvmfs/software.eessi.io/versions/2025.06/software/linux/x86_64/intel/haswell/software/libidn2/2.3.8-GCCcore-14.3.0/lib/../lib64/libidn2.so.0.4.0

Instantiating CDLL object for libc.so
<CDLL '/cvmfs/software.eessi.io/versions/2025.06/compat/linux/x86_64/lib64/libc.so.6', handle 7c490b815b90 at 0x7c490ab37230>
Running LoadLibrary for libc.so
<CDLL '/cvmfs/software.eessi.io/versions/2025.06/compat/linux/x86_64/lib64/libc.so.6', handle 7fdb32891b90 at 0x7fdb31fa3230>
Running find_library for libc.so
/cvmfs/software.eessi.io/versions/2025.06/compat/linux/x86_64/lib64/libc.so.6

Instantiating CDLL object for libc.so.6
<CDLL '/cvmfs/software.eessi.io/versions/2025.06/compat/linux/x86_64/lib/../lib64/libc.so.6', handle 71889e318b90 at 0x71889d737230>
Running LoadLibrary for libc.so.6
<CDLL '/cvmfs/software.eessi.io/versions/2025.06/compat/linux/x86_64/lib/../lib64/libc.so.6', handle 740520efdb90 at 0x74052060f230>
Running find_library for libc.so.6
/cvmfs/software.eessi.io/versions/2025.06/compat/linux/x86_64/lib/../lib64/libc.so.6

Instantiating CDLL object for /cvmfs/software.eessi.io/versions/2025.06/software/linux/x86_64/intel/haswell/software/libidn2/2.3.8-GCCcore-14.3.0/lib64/libidn2.so
<CDLL '/cvmfs/software.eessi.io/versions/2025.06/software/linux/x86_64/intel/haswell/software/libidn2/2.3.8-GCCcore-14.3.0/lib64/libidn2.so', handle 200ed700 at 0x758d79537230>
Running LoadLibrary for /cvmfs/software.eessi.io/versions/2025.06/software/linux/x86_64/intel/haswell/software/libidn2/2.3.8-GCCcore-14.3.0/lib64/libidn2.so
<CDLL '/cvmfs/software.eessi.io/versions/2025.06/software/linux/x86_64/intel/haswell/software/libidn2/2.3.8-GCCcore-14.3.0/lib64/libidn2.so', handle ae027c0 at 0x7944ae7e3230>

Instantiating CDLL object for /cvmfs/software.eessi.io/versions/2025.06/compat/linux/x86_64/lib64/libc.so.6
<CDLL '/cvmfs/software.eessi.io/versions/2025.06/compat/linux/x86_64/lib64/libc.so.6', handle 7c6f15e95b90 at 0x7c6f155a7230>
Running LoadLibrary for /cvmfs/software.eessi.io/versions/2025.06/compat/linux/x86_64/lib64/libc.so.6
<CDLL '/cvmfs/software.eessi.io/versions/2025.06/compat/linux/x86_64/lib64/libc.so.6', handle 71e288483b90 at 0x71e287b93230>

@casparvl casparvl merged commit deb72dd into easybuilders:develop Jan 21, 2026
8 checks passed
@bedroge bedroge deleted the python_ctypes_patch branch January 21, 2026 20:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2025b issues & PRs related to 2025b common toolchains 2026.1 issues & PRs related to 2026.1 common toolchains bug fix change EESSI Related to EESSI project

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants