I'm trying to include C++ header and source files in my Python package because I use them in the Python files of my package (via cppyy). It works fine on my local PC, but when I build the package for PyPI, install and import it, I get an error that the headers/C++ files don't exist:
import eefpy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/root/tests/venv/lib/python3.10/site-packages/eefpy/__init__.py", line 2, in <module>
cppyy.include('solver/eef.h')
File "/root/tests/venv/lib/python3.10/site-packages/cppyy/__init__.py", line 267, in include
raise ImportError('Failed to load header file "%s"%s' % (header, err.err))
ImportError: Failed to load header file "solver/eef.h"
input_line_18:1:10: fatal error: 'solver/eef.h' file not found
#include "solver/eef.h"
^~~~~~~~~~~~~~
I tried to add the folder that includes the C++ files in the setup.py file as follows:
...
include_package_data=True,
package_data={
'eefpy': ['../solver/*'],
},
...
I also tried adding the folder/files to MANIFEST.in:
recursive-include solver *
This builds the package and includes the solver folder, but it saves it outside the main package directory in the installed package, so when I install it in my virtual environment, I see it under site-packages as a separate directory, not within the package.
I expected the C++ files to be included within the package directory (e.g., eefpy/solver/) so that they are accessible when the package is installed and imported.
package_data={'eefpy': ['../solver/*'],},— you included package data from outside the package sopipbuilds an sdist/wheel with the directory outside the package. If you want to have it as a subdirectory ofeefpyorcppyyit must be a subdirectory at the time of sdist/wheel building. At the installation timepipstrictly mimics what it saw at build time.setup.pyto move files around when building the sdist, but that would be some work, so if that is what you want say it clearly in the question.