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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:52:02+00:00 2026-05-20T05:52:02+00:00

Take Django for instance, in manage.py : try: import settings except ImportError: sys.stderr.write(Error: Can’t

  • 0

Take Django for instance, in manage.py:

try:
    import settings
except ImportError:
    sys.stderr.write("Error: Can't find the file 'settings.py'...")

Seems legit, but what happens when settings imports non_existant_lib_foo?

Well, you’re sent on a goose chase for all the possible things you could have done with PATH, etc.

Of course you can use except ImportError as e: and just print out the actual error message, but what if you want to catch only a specific error and give a really good bit of advice, like above?

You’re left to using regexp more or less or, at best, guessing that the “right” module failed importing, and then display the message.

Is there a better way to handle this?

  • 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-20T05:52:03+00:00Added an answer on May 20, 2026 at 5:52 am

    Basically the problem is that your error message is wrong – there are other reasons why import can fail, not just wrong paths. ImportError simply means “you cannot use this module, look at the traceback to find out why”, you just jumped to a conclusion.

    If you want to display “Can’t find the file” then you should look for the file first. imp.find_module does that.

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

Sidebar

Related Questions

I am sending an AJAX request to a Django view that can potentially take
When I run manage.py shell on my Django project to take a peek at
Let's take the Django tutorial. In the first part we can find this model:
Is there a good Django app out there that can take a list of
On my django app I have a report (a csv download) that can take
I'm altering django-taggit so that it is not case sensitive. I want to take
Take a look at this: http://thebekker.dk/_skole/GFeksamen/ You can see the 2nd menu item show
Is it possible to have Apache htaccess rewrites take effect before it hits django?
My Django unit tests take a long time to run, so I'm looking for
Django 1.2 allows usernames to take the form of an email address. Changed in

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.