OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

How to include C++ header and source files in a Python package for PyPI distribution?

  • Thread starter Thread starter oriyalp
  • Start date Start date
O

oriyalp

Guest
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:

Code:
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:

Code:
...
include_package_data=True,
package_data={
    'eefpy': ['../solver/*'],
},
...

I also tried adding the folder/files to MANIFEST.in:

Code:
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.
<p>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:</p>
<pre><code>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"
^~~~~~~~~~~~~~
</code></pre>
<p>I tried to add the folder that includes the C++ files in the <code>setup.py</code> file as follows:</p>
<pre><code>...
include_package_data=True,
package_data={
'eefpy': ['../solver/*'],
},
...
</code></pre>
<p>I also tried adding the folder/files to <code>MANIFEST.in</code>:</p>
<pre><code>recursive-include solver *
</code></pre>
<p>This builds the package and includes the <code>solver</code> 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 <code>site-packages</code> as a separate directory, not within the package.</p>
<p>I expected the C++ files to be included within the package directory (e.g., <code>eefpy/solver/</code>) so that they are accessible when the package is installed and imported.</p>
 

Latest posts

H
Replies
0
Views
1
haifisch123
H
A
Replies
0
Views
1
Adrian-Mihai Enache
A
H
Replies
0
Views
1
Hür Doğan ÜNLÜ
H
Top