-
Notifications
You must be signed in to change notification settings - Fork 2.2k
docs: add a note about compiling the example #2737
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
When pybind11 is included as a submodule, the user needs to update their Python module search path. Otherwise, the first c++ compilation command in docs/basics.rst will fail.
This bit of documentation may be helpful to new users. It would have been helpful to me when I first went through the instructions in the doc. If you believe so, feel free to rewrite it as you see fit and discard this pull request. |
I believe the idea is that if you use pybind11 as a git submodule, that you don't install it through pip. So you don't need to call I don't even know if |
Yes, it is supposed to work, though I would do it this way: https://github.com/scikit-hep/boost-histogram/blob/ca298e7c9008025191e94a927fbd0d1bd012b97f/setup.py#L11-L14 Or, better yet, refer to the docs here under "Suggested usage if you have pybind11 as a submodule": https://pybind11.readthedocs.io/en/stable/compiling.html#copy-manually :) You should never be setting PYTHONPATH if you are building a library, and an install step must be self contained and not depend on the users environment. |
Ahh, you are looking at building it by hand, but using it as a submodule? You generally should always be using setuptools or CMake if you are working with a library containing a submodule, not building it by hand. That's just a demo to show you how it works and prove it is simple. If you do want to build it by hand but you don't want to install it, then sure, but I don't think it needs to be in the docs. An end-user can use PYTHONPATH, though I still recommend staying away from it. |
That's a good point @YannickJadoul. Maybe it would be better to update docs/basics.rst to show how to do the c++ compilation when using pybind11 as a Git submodule. Currently that command is
|
It's best written as |
Or |
I also prefer |
c++ -shared -std=c++11 -fPIC $(python3-config --cflags) <path to pybind11/include> example.cpp \
-o example$(python3-config --extension-suffix) I think is the full, correct way to do it all in one line. For me, it expands to: c++ -shared -std=c++11 -fPIC -I/usr/local/Cellar/[email protected]/3.9.1/Frameworks/Python.framework/Versions/3.9/include/python3.9 \
-I/usr/local/Cellar/[email protected]/3.9.1/Frameworks/Python.framework/Versions/3.9/include/python3.9 \
-Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG \
-g -fwrapv -O3 -Wall -I/usr/local/include \
-I/Library/Developer/CommandLineTools/SDKs/MacOSX11.0.sdk/usr/include \
-I/Library/Developer/CommandLineTools/SDKs/MacOSX11.0.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers \
<path to pybind11/include> example.cpp -o example.cpython-39-darwin.so But why are we doing this by hand instead in CMake or setuptools? And why are you expecting |
That command looks good Henry. You would just need to put the I'm not sure why Regarding doing it by hand, this is just what a first-time visitor to the doc might try when following the demo. |
Maybe we could just add a note that pybind11 should be installed for these |
Or maybe a note to use |
This note shows how to modify the compilation command for the example when the pybind11 source has been included as a Git submodule.
Added an internal link to the docs
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.
Looks much better. Let's get at least one more approval before merging, though.
docs/basics.rst
Outdated
.. note:: | ||
|
||
If you used :ref:`include_as_a_submodule` to install the pybind11 source, | ||
then use ``$(python3-config --includes) -Iextern/pybind11/include`` |
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.
-I
should really be -isystem
.
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.
I agree, but the pybind11-config and the Python-config both use -I
I believe, so it would be a little odd if this causes pybind11 to be system but not Python.h.
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.
then use ``$(python3-config --includes) -Iextern/pybind11/include`` | |
then use ``$(python3-config --includes) -isystem extern/pybind11/include`` |
For a simple example, not sure this is best, but it's also better to show the correct thing if it's visible.
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.
Hm... You're right that pybind11-config
and python-config
both use -I
. I'd argue that both of those are wrong. I personally use -isystem /usr/include/python3.9
and my cmake adds both with SYSTEM
.
Anyway, I'm not super determined to change this -I
to -isystem
.
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.
Thanks, @ssiano! This seems both more correct, and in a better place (i.e., under manual compiling, rather than seemingly suggesting to manually compile a submodule; CMake should still be preferred, if possible, I think) :-)
Now I'm thinking that any new note in "First steps" should reference the comments in https://pybind11.readthedocs.io/en/latest/compiling.html#building-manually. So please don't merge this for now. |
Those probably should be |
Then convert to draft. :) |
Also updated the command substitution syntax for consistency
Thanks! |
When pybind11 is included as a submodule, the user needs to update their
Python module search path. Otherwise, the first c++ compilation command
in docs/basics.rst will fail.