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 8244491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T21:52:07+00:00 2026-06-07T21:52:07+00:00

I have several python modules (organized into packages), which depend on each other .

  • 0

I have several python modules (organized into packages), which depend on each other. e.g.

  • Module1
  • Module2: imports Module1
  • Module3
  • Module4: imports Module3, Module 2, Module 1

Let’s assume the relevant interface to develop applications is in Module4 and I want to generate a Module4.so using cython.
If I proceed in the naive way, I get an extension Module4.so which I can import BUT the extension relies on the python source code of Module1, Module2, Module3.

Is there a way to compile so that also Module1,Module2, Module3 are compiled and linked to Module4? I would like to avoid doing everything manually, e.g. first compile Module1.so then change import declaration in Module2, so as to import Module1.so rather than Module1.py, then compile Module2 into Module2.so and so on….

  • 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-07T21:52:09+00:00Added an answer on June 7, 2026 at 9:52 pm

    Edit. First two options refer to Cython’s specific code, what I’ve missed is that the question is about pure python modules, so option 3 is the solution.

    There are a few options:

    1.
    See this “How To Create A Hierarchy Of Modules In A Package”:
    https://github.com/cython/cython/wiki/PackageHierarchy

    2.
    I prefer the “include” statement:
    http://docs.cython.org/src/userguide/language_basics.html#the-include-statement
    I have many .pyx files and they are all included in main.pyx, it’s all in one namespace. The result is one big module: http://code.google.com/p/cefpython/source/browse/cefpython.pyx

    3.
    You can compile all your modules at once using setup by adding more than one “Extension”:

    setup(
        cmdclass = {'build_ext': build_ext},
        ext_modules = [Extension("example", sourcefiles), Extension("example2", sourcefiles2), Extension("example3", sourcefiles3)]
    )
    

    4.
    A more efficent compilation – see here.

    setup (
        name = 'MyProject',
        ext_modules = cythonize(["*.pyx"]),
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Guys, I have much python code in modules which are resides in several python
I have two Python packages where one needs to be imported by the other.
I have a Python program that consists of several modules. The main module creates
I have several modules that are within a Python package: # my_package contents __init__.py
I have a python-based GTK application that loads several modules. It is run from
I have several python.exe processes running on my Vista machine and I would like
I have a batch file that runs several python scripts that do table modifications.
I have a python program that opens several urls in seperate tabs in a
I do not fully understand classes. I have read the python documentation and several
we have several tens of macro enabled excel files, each of those contains few

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.