GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — bpo-36721: Add --embed option to python-config by vstinner · Pull Request #13500 · python/cpython

Conversation

@vstinner

@vstinner vstinner commented May 22, 2019 •
edited by bedevere-bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

To embed Python into an application, a new --embed option must be
passed to "python3-config --libs --embed" to get "-lpython3.8" (link
the application to libpython). To support Python 3.7 and older, try
"python3-config --libs" (without --embed) on failure.

Add a pkg-config "python-3.8-embed" module to embed Python into an
application: "pkg-config python-3.8-embed --libs" includes
"-lpython3.8". To support Python 3.7 and older, try "pkg-config
python-X.Y --libs" (without "-embed") on failure (replace X.Y with
the Python version).

On the other hand, "pkg-config python3.8 --libs" no longer contains
"-lpython3.8". C extensions must not be linked to libpython (except
on Android, case handled by the script); this change is backward
incompatible on purpose.

"make install" now also installs "python-3.8-embed.pc".

https://bugs.python.org/issue36721

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@vstinner
vstinner requested a review from ned-deily May 22, 2019 15:02
@the-knights-who-say-ni the-knights-who-say-ni added the CLA signed label May 22, 2019
@bedevere-bot bedevere-bot added the awaiting core review label May 22, 2019
@vstinner

vstinner commented May 22, 2019

Copy link
Copy Markdown
Member Author

I tested with:

./configure CFLAGS="-O0" --enable-shared --prefix=/opt/py38
make
make install

Commands without -lpython, build a C extension:

$ /opt/py38/bin/python3.8-config --libs
 -lcrypt -lpthread -ldl  -lutil -lm -lm 

# empty output (expected result),
$ pkg-config python-3.8 --libs 

Commands with -lpython, embed Python into an applicaton:

$ /opt/py38/bin/python3.8-config --libs --embed
-lpython3.8 -lcrypt -lpthread -ldl  -lutil -lm -lm 

$ pkg-config python-3.8-embed --libs 
-L/opt/py38/lib -lpython3.8
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner

vstinner commented May 22, 2019

Copy link
Copy Markdown
Member Author

@hroncok @xdegaye: Would you mind to review (may also test?) this change? I marked https://bugs.python.org/issue36721 as a release blocker.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner

vstinner commented May 22, 2019

Copy link
Copy Markdown
Member Author

cc @doko42

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

hroncok
hroncok reviewed May 22, 2019
View reviewed changes
Comment thread Doc/whatsnew/3.8.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/whatsnew/3.8.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

@vstinner
bpo-36721: Add --embed option to python-config
a588843
To embed Python into an application, a new --embed option must be
passed to "python3-config --libs --embed" to get "-lpython3.8" (link
the application to libpython). To support both 3.8 and older, try
"python3-config --libs --embed" first and fallback to "python3-config
--libs" (without --embed) if the previous command fails.

Add a pkg-config "python-3.8-embed" module to embed Python into an
application: "pkg-config python-3.8-embed --libs" includes
"-lpython3.8".  To support both 3.8 and older, try "pkg-config
python-X.Y-embed --libs" first and fallback to "pkg-config python-X.Y
--libs" (without --embed) if the previous command fails (replace
"X.Y" with the Python version).

On the other hand, "pkg-config python3.8 --libs" no longer contains
"-lpython3.8". C extensions must not be linked to libpython (except
on Android, case handled by the script); this change is backward
incompatible on purpose.

"make install" now also installs "python-3.8-embed.pc".
@vstinner

vstinner commented May 22, 2019

Copy link
Copy Markdown
Member Author

I amended (and rebased) my commit to be able to update the commit to address @hroncok review.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@xdegaye

xdegaye commented May 22, 2019

Copy link
Copy Markdown
Contributor

As expected, all python-config commands print the argument to link against libpython on Android when python is built with this PR (in case you wonder, pthread is not printed as it is part of libc on Android):

generic_x86_64:/data/local/tmp/python $ sh bin/python3.8-config --libs
-lpython3.8d -ldl  -lm -lm
generic_x86_64:/data/local/tmp/python $ sh bin/python3.8-config --libs --embed
-lpython3.8d -ldl  -lm -lm
generic_x86_64:/data/local/tmp/python $ bin/python lib/python3.8/config-3.8d/python-config.py --libs
-lpython3.8d -ldl -lm -lm
generic_x86_64:/data/local/tmp/python $ bin/python lib/python3.8/config-3.8d/python-config.py --libs --embed
-lpython3.8d -ldl -lm -lm

pkg-config is not installed, so could not be tested.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

xdegaye
xdegaye reviewed May 22, 2019
View reviewed changes

@xdegaye xdegaye left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Just a nit-pick

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Misc/python-config.sh.in Resolved

Uh oh!

There was an error while loading. Please reload this page.

@vstinner
python-config.sh.in: avoid quotes
1f8ca26
@vstinner

vstinner commented May 22, 2019

Copy link
Copy Markdown
Member Author

As expected, all python-config commands print the argument to link against libpython on Android when python is built with this PR (...)

Yeah, it's the expected behavior. But I asked you to double check just in case :-) I'm not confident when I modify the build system. Thanks!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner
Fix pkg-config descriptions!
858bc9d
@hroncok

hroncok commented May 22, 2019

Copy link
Copy Markdown
Contributor

Should we try to implement the waf part before this is merged to see how possible it is?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner

vstinner commented May 22, 2019

Copy link
Copy Markdown
Member Author

Should we try to implement the waf part before this is merged to see how possible it is?

Are you talking about the code to handle Python 3.8 and older version? The fallback described in the documentation should be trivial to implement, no? Why would it be not possible?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@hroncok

hroncok commented May 22, 2019

Copy link
Copy Markdown
Contributor

It should be entirely possible. It was just an idea.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner
Fix make distclean: remove generated Misc/python-embed.pc
2291465
@vstinner
vstinner merged commit 0a8e572 into python:master May 23, 2019
@bedevere-bot bedevere-bot removed the awaiting core review label May 23, 2019
@vstinner
vstinner deleted the embed branch May 23, 2019 01:30
@vstinner

vstinner commented May 23, 2019

Copy link
Copy Markdown
Member Author

Even if I'm not confident in my change (add --embed option), I chose to merge it anyway since at least "waf" build system is broken by my other changes (no longer link C extensions to libpython). I would like to get this change into Python 3.8 beta1 to attempt to fix most applications embedding Python.

Anyway, if something goes wrong, we still have plenty of time to decide what to do before 3.8.0 final, scheduled for 2019-10-21: https://www.python.org/dev/peps/pep-0569/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@hroncok

hroncok commented May 24, 2019 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

This is what it gave me in Fedora, feels a bit inconsistent:

   /usr/lib64/pkgconfig/python-3.8-embed.pc
   /usr/lib64/pkgconfig/python-embed-3.8d.pc
   /usr/lib64/pkgconfig/python3-embed.pc
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner

vstinner commented May 24, 2019

Copy link
Copy Markdown
Member Author

Should be fixed by PR #13551 :-)

hroncok reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@namhyung namhyung mentioned this pull request Sep 20, 2020
Python3 config trouble namhyung/uftrace#1197
Closed
@eryngion eryngion mentioned this pull request Dec 30, 2023
gdb: fix cross-compile with python NixOS/nixpkgs#275731
Open
13 tasks
@mcepl mcepl mentioned this pull request Jun 6, 2024
Some changes to make building possible SUSE-Enceladus/cloud-regionsrv-client#160
Closed
@encukou encukou mentioned this pull request Jun 18, 2025
python-config --embed documentation #83463
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@ned-deily ned-deily Awaiting requested review from ned-deily
2 more reviewers
@hroncok hroncok hroncok left review comments
@xdegaye xdegaye xdegaye left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@vstinner @xdegaye @hroncok @the-knights-who-say-ni @bedevere-bot
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.