4

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.

2
  • 1
    package_data={'eefpy': ['../solver/*'],}, — you included package data from outside the package so pip builds an sdist/wheel with the directory outside the package. If you want to have it as a subdirectory of eefpy or cppyy it must be a subdirectory at the time of sdist/wheel building. At the installation time pip strictly mimics what it saw at build time. Commented Jun 25, 2024 at 20:08
  • 1
    What "package data" means is "data inside an importable package". So the files must be within an importable package of your project. Setuptools will not move the files inside the import package, they already must be there before building the distributions (sdist and wheel). Technically you could instruct setup.py to 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. Commented Jun 25, 2024 at 21:03

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.