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

  • Home
  • SEARCH
  • 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 651223
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:08:22+00:00 2026-05-13T22:08:22+00:00

I have written a Python module, and I have two versions: a pure Python

  • 0

I have written a Python module, and I have two versions: a pure Python implementation and a C extension. I’ve written the __init__.py file so that it tries to import the C extension, and if that fails, it imports the pure Python code (is that reasonable?).

Now, I’d like to know what is the best way to distribute this module (e.g. write setup.py) so it can be easily used by people with or without the facility to build, or use, the C extension, just by running:

python setup.py install

My experience is limited, but I see two possible cases:

  • User does not have MS Visual Studio, or the GCC compiler suite, installed on their machine, to build the C extension
  • User is running IronPython, Jython, or anything other than CPython. I only have used CPython. So I’m not sure how I could distribute this module so that it would work smoothly and be easy to install on those platforms, if they’re unable to use the C extension.
  • 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-05-13T22:08:22+00:00Added an answer on May 13, 2026 at 10:08 pm

    (is that reasonable?).

    Yep, perfectly sensible.

    To catch the “no suitable C compiler case”: the call to setup(...) will do a sys.exit in case of problems. So, first try it with the ext_modules argument set as desired, within a try:

    try:
      setup(..., ext_modules=...)
    except SystemExit: ...
    

    and in the except clause, call setup(...) again without the ext_modules (so it gives up on building and installing the extensions). The user who’s installing will still see messages like “unable to execute gcc-4.0: No such file or directory”, but you can appropriately add your own messages to inform the user that it’s no big deal and that you’re trying again without the extension modules.

    To support non-CPython implementations, in your setup.py you can test sys.version (I’m not sure what the value will be for each non-CPython implementation, but IronPython has an 'IronPython' substring there, for example), to avoid even trying the ext_modules part. If you miss some such implementation in your checks, the try/except should probably catch most others anyway, just with a modest amount of wasted work;-).

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

Sidebar

Ask A Question

Stats

  • Questions 534k
  • Answers 534k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer CRAN only distributes source for Unix, in other words no… May 17, 2026 at 12:51 am
  • Editorial Team
    Editorial Team added an answer I don't know much about classic ASP and don't know… May 17, 2026 at 12:51 am
  • Editorial Team
    Editorial Team added an answer Will emit the remote being tracked: git config branch.<branchname>.remote Will… May 17, 2026 at 12:51 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Is there a module written purely in Python that will allow a script to
I have written a Python extension library in C and I am currently using
I've written two python scripts script1.py and script2.py. I want to run script1.py from
I'm developing a Django app, and I'm trying to use Python's logging module for
I have a feeling this will be a quick fix, given that I started
Python has a flag -O that you can execute the interpreter with. The option
I have a list of strings that are all early modern English words ending
As the title suggests, I'm working on a site written in python and it
I have been programming in python exclusively for 4 years and have never really
While I've written unit tests for most of the code I've done, I only

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.