Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9042157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T10:24:59+00:00 2026-06-16T10:24:59+00:00

What is the simplest way to create a pxd definition file, which simply collects

  • 0

What is the simplest way to create a pxd definition file, which simply collects cdefs replicated over pyx files, without creating new extensions?

My case is the following: I would like to gather some extern cdefs in a pxd file (hp/src/common.pxd). I’ve also added some non-extern cdef, whose implementation is in common.pyx.

In another pyx file (hp/src/_lib.pyx), which I turn into an extension, I cimport some stuff from common.

In the setup.py file I create the following extension:

Extension('hp._lib', 
          ['hp/src/_lib.pyx'],
          language='c++'),

By doing so, no common.cpp file is created, so it looks like dependencies are not automatically handled. That’s the first problem.

Then, manually running ‘cython –cplus common.pyx’ correctly creates a common.cpp file in the directory hp/src, and if I add ‘hp/src/common.cpp’ to the list of the extension sources, the command python setup.py installs everything without complaint, but then, importing the module hp triggers an ImportError: No module named common… from _lib.cpp…
I’m stuck here. Any idea?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T10:25:00+00:00Added an answer on June 16, 2026 at 10:25 am

    You can include material from another file using the include statement.

    See the documentation here:

    http://docs.cython.org/src/userguide/language_basics.html#the-include-statement

    If you have external definitions in common.pxd and implementations in commond.pyx you will need to include them both. For example, in _lib.pyx:

    include "common.pxd"
    include "common.pyx"
    

    The contents of these files will then be compiled into your _lib module as if they were textually included at that point. i.e. a common.c file will not be generated, but rather included with _lib.c.

    The Cython compiler doesn’t recognise changes to includes when deciding if the .c file for the module needs to be regenerated, so remember to delete this before you recompile.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What's the simplest/canonical way to create an empty file in C#/.NET? The simplest way
What's the simplest way to create and write to a (text) file in Java
What is the simplest way to create a Django template tag which displays the
What is the simplest way to create AffineTransform which maps coordinates from one rectangle
Would the simplest way to create a threadpool (or, at least obtain the code
What is the simplest way to dynamically create a hidden input form field using
What is the easiest/simplest way to delay inside a function without having to delay
What's the simplest way to list all the files in a git repo a
what is the best and most simplest way to create tooltip text for textboxes
I am trying my hardest to find the simplest way to create a basic

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.