Skip to main content

find_libpython

A pypi project version of this gist, which also appears within the PyCall library.

The library is designed to find the path to the libpython dynamic library for the current Python environment. It should work with many types of installations, whether it be conda-managed, system-managed, or otherwise. And it should function on Windows, Mac OS/OS X, and any Linux distribution.

This code is useful in several contexts, including projects that embed a Python interpreter into another process, or Python library build systems.

Usage

find_libpython is both a script and a Python package. Usage as a script is useful in contexts like obtaining the path to libpython for linking in makefile-based build systems. It could also be used to determine the path to libpython for embedding a Python interpreter in a process written in another language. In that case the recommended usage is to simply call the script in a subprocess with no arguments and parse the output.

> find_libpython
/home/kaleb/miniconda3/envs/test/lib/libpython3.8.so.1.0

The full help message:

> find_libpython --help
usage: find_libpython [-h] [-v] [--list-all | --candidate-names | --candidate-paths | --platform-info | --version]

Locate libpython associated with this Python executable.

options:
  -h, --help         show this help message and exit
  -v, --verbose      Print debugging information.
  --list-all         Print list of all paths found.
  --candidate-names  Print list of candidate names of libpython.
  --candidate-paths  Print list of candidate paths of libpython.
  --platform-info    Print information about the platform and exit.
  --version          show program's version number and exit

Usage as a library might occur when you need to obtain the path to the library in a Python-based build system like distutils. It is recommended to use the find_libpython method which will return the path to libpython as a string, or None if it cannot be found.

>>> from find_libpython import find_libpython
>>> find_libpython()
'/home/kaleb/miniconda3/envs/test/lib/libpython3.8.so.1.0'

Release files for find-libpython 0.5.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for find-libpython 0.5.1
File Size Uploaded
find_libpython-0.5.1.tar.gz 9.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for find-libpython 0.5.1
File Interpreter ABI Platform
find_libpython-0.5.1-py3-none-any.whl Python 3 none any Details

Total release size: 18.6 kB

Release files / find_libpython-0.5.1.tar.gz

Download URL find_libpython-0.5.1.tar.gz
Size 9.4 kB
Tags Source
SHA-256 checksum
How to use checksums
12a0fb39ff8dcc64ad0fd554b1bd142ea4a8c4c18e5da6043a547ce7b25559fe
BLAKE2b-256 checksum
How to use checksums
7060951b7ca316ab3ec928ed788de5fcb30b4a0292704e50b872c8edf24c11fe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release files / find_libpython-0.5.1-py3-none-any.whl

Download URL find_libpython-0.5.1-py3-none-any.whl
Size 9.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
723a8cfe6fed255a1f58b53c62ed556fb340ec0d456e9863ebc01a5cc047607d
BLAKE2b-256 checksum
How to use checksums
341f1d6079f4f0540aaa368aa20d89d98eda42f081c397a822c547340e32d1e3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

0.5.1 This release

2 release files

0.5.0

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page