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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:49:57+00:00 2026-05-22T19:49:57+00:00

Python 2.6 and beyond has the ability to directly execute a .zip file if

  • 0

Python 2.6 and beyond has the ability to directly execute a .zip file if the zip file contains a __main__.py file at the top of the zip archive. I’m wanting to leverage this feature to provide preview releases of a tool I’m developing that won’t require users to install anything beyond copying the .zip file to their disk. Is there a standard way to create such a zip file? I’m looking for a solution that works with python 2.6 and python 2.7.

Ideally I would like to use distutils, since I already have it working when I want to do a normal install. Is there a canonical way to use (or extend) distutils to create such a .zip file?

distutils provides an sdist command which creates a source distribution that is almost right, but creates a structure that is a little too deep.

For example, my source tree looks like this:

my_package/
  - setup.py
  - src/
      - __main__.py
      - module1/
      - module2/
      - module3/

When I do python setup.py sdist I end up with a .zip file with the following structure:

my_package-0.1.zip
  - my_package-0.1/
      - README.txt
      - PKG_INFO
      - src/
          - __main__.py
          - module1/
          - module2/
          - module3/

This isn’t executable because __main__.py is not at the top of the distribution. Effectively what I want is a src distribution that doesn’t include src, but only the files under src. That, or exactly what sdist gives me, but with an extra __main__.py at the top of the archive.

  • 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-22T19:49:58+00:00Added an answer on May 22, 2026 at 7:49 pm

    Updated: Since the setup.cfg is global, it affects the ‘install-lib’ setting for all commands, which is not what is desired. Unfortunately there is no way (to my knowledge) to pass a options to a subcommand via the command line, e.g. if you specify bdist --install-lib=/ it will raise an error instead of passing that down to the subcommands.

    To customize the install-lib for the install subcommand only when bdist is run, you can subclass the bdist_dumb command and set the path manually after the install subcommand is constructed / reinitialized:

    setup.py

    from distutils.core import setup
    from distutils.command.bdist_dumb import bdist_dumb
    
    class custom_bdist_dumb(bdist_dumb):
    
        def reinitialize_command(self, name, **kw):
            cmd = bdist_dumb.reinitialize_command(self, name, **kw)
            if name == 'install':
                cmd.install_lib = '/'
            return cmd
    
    if __name__ == '__main__':
        setup(
            # our custom class override
            cmdclass = {'bdist_dumb': custom_bdist_dumb},
            name='my_package',
            py_modules = ['__main__'],
            packages = ['module1', 'module2'],
            package_dir = {'': 'src'}
        )
    

    Running:

    % python setup.py bdist --format=zip
    % unzip -l dist/my_package-0.0.0.linux-x86_64.zip
    Archive:  dist/my_package-0.0.0.linux-x86_64.zip
      Length      Date    Time    Name
    ---------  ---------- -----   ----
          184  2011-05-31 20:34   my_package-0.0.0.egg-info
           30  2011-05-31 20:34   __main__.py
          128  2011-05-31 20:34   __main__.pyc
          107  2011-05-31 20:34   module1/__init__.pyc
            0  2011-05-31 20:27   module1/__init__.py
          107  2011-05-31 20:34   module2/__init__.pyc
            0  2011-05-31 20:27   module2/__init__.py
    ---------                     -------
          556                     7 files
    
    % python dist/my_package-0.0.0.linux-x86_64.zip
    my_package working.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Python has this wonderful way of handling string substitutions using dictionaries: >>> 'The %(site)s
Python's standard library has modules for configuration file parsing ( configparser ), environment variable
Python gives us the ability to create 'private' methods and variables within a class
Python's IDLE has 'Check Module' (Alt-X) to check the syntax which can be called
Python's f.tell doesn't work as I expected when you iterate over a file with
Python: Unpack from hex to double This is the value value = ['\x7f', '\x15',
Python docs mention this word a lot and I want to know what it
Python has many GUI toolkits . If I understand correctly, these toolkits typically take
I need to develop a file indexing application in python and wanted to know
I have been working in Python for a few months now, and it has

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.