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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T07:06:00+00:00 2026-06-11T07:06:00+00:00

I’m installing a package using setup.py: python setup.py install My __init__.py in the package

  • 0

I’m installing a package using setup.py:

python setup.py install

My __init__.py in the package I’m installing includes some package level checks, one of it checks whether an attribute is available in settings.py. Since it is a redistributable package the settings.py is not delivered via the package, but the user has to take care that the settings are correctly set in their project wide settings.py.

from django.core.exceptions import ImproperlyConfigured
from django.conf import settings

#check if settings are properly set
if not hasattr(settings, 'PACKAGE_SPECIFIC_SETTING'):
    raise ImproperlyConfigured('Please add the PACKAGE_SPECIFIC_SETTING setting to your settings.py')

Now I’m wondering why the call setup.py install runs my __init__.py (and crashes because it, not very surprisingly, does not find any settings.)

I would have expected that setup.py only copies my package and does not run any code. The code should be run whenever another app using my package imports my package into his code.

Edit: Included setup.py as requested

#!/usr/bin/env python
# vim: ai ts=4 sts=4 et sw=4 coding=utf-8


from distutils.core import setup

setup(
    name='django-simple-lock',
    version=__import__('lock').__version__,
    license = 'GNU Lesser General Public License (LGPL), Version 3',

    requires = ['python (>= 2.5)', 'django (>= 1.3)'],
    provides = ['lock'],

    description='Simple locking implementation as a reusable'
                'Django app.',
    long_description=open('README.rst').read(),

    url='http://github.com/mr-stateradio/django-simple-lock',

    packages=['lock', 'lock.tests'],

    classifiers = [
        'Development Status :: 4 - Beta',
        'Environment :: Web Environment',
        'Framework :: Django',
        'Intended Audience :: Developers',
        'License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL)',
        'Programming Language :: Python',
        'Topic :: Database',
        'Topic :: Software Development :: Libraries :: Python Modules',
    ],
)

Edit: Included traceback:

/Users/Me/.virtualenvs/django1_4/bin/python setup.py install
Traceback (most recent call last):
  File "setup.py", line 9, in <module>
    version=__import__('lock').__version__,
  File "/01_Development/django-simple-lock/lock/__init__.py", line 8, in <module>
    raise ImproperlyConfigured('Please add the PACKAGE_SPECIFIC_SETTING setting to your settings.py')
  • 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-11T07:06:02+00:00Added an answer on June 11, 2026 at 7:06 am

    Your setup.py is executable python. It is run as a python script to discover your package distribution configuration.

    Your setup.py runs this code:

        version=__import__('lock').__version__,
    

    This imports your lock package, so the __init__.py file in that package is loaded. Remove that call and your setup will succeed. Store the version somewhere else instead.

    Note that the trackback even tells you so explicitly:

      File "setup.py", line 9, in <module>
        version=__import__('lock').__version__,
    

    Best practice is to store the version in the setup.py file instead (some examples here and here). The Django project does use the __import__ trick, but it’s __init__.py only contains the version information, nothing else.

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

Sidebar

Related Questions

I am reading a book about Javascript and jQuery and using one of the
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build

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.