Skip to main content

Finds the libpython associated with your environment, wherever it may be hiding

Project description

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'

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

find_libpython-0.5.0.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

find_libpython-0.5.0-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

Details for the file find_libpython-0.5.0.tar.gz.

File metadata

  • Download URL: find_libpython-0.5.0.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for find_libpython-0.5.0.tar.gz
Algorithm Hash digest
SHA256 4e4e0ffcad3bfaf2af9461b359329b8736e3f721dc375da7c167aff383e56be1
MD5 f3c8dceb14bce89123012c0a01d2e688
BLAKE2b-256 f946c466b94830bb77ef1e715d869246b9f8e111f9b2f4de2c60d4de1b986779

See more details on using hashes here.

File details

Details for the file find_libpython-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: find_libpython-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 9.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for find_libpython-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7690dcf6442cdce39c0df191903fd5ecf9af437fa920effb6569fbf2c8ca8ab4
MD5 20329ef78544132d8e99abecde532c97
BLAKE2b-256 a73f0eb94bfca99e54404901536ea8c80ddacff4953257514c6b8fb01f9a75a8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page