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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:33:56+00:00 2026-05-27T18:33:56+00:00

Suppose I have a python package called mypackage, which has a series of scripts.

  • 0

Suppose I have a python package called mypackage, which has a series of scripts. Once mypackage is in the site-packages dir, the user can refer to various Python files within mypackage as mypackage.submodule1, mypackage.submodule2 from Python, as usual. However, some of these are scripts that are meant to be called from the command line. In submodule1 for example, I have:

== mypackage/submodule1.py ==

if __name__ == '__main__':
  main()

def main():
  # parse command line options here, do stuff

How can I properly distribute/package mypackage so that the user can cleanly use these submodules as command line scripts once “mypackage” is in their path? I would have thought you can do:

python mypackage.submodule1.py arg1 arg2 ...

but this syntax is invalid. In other words, how can the user refer to submodules of my package as scripts rather than importing them from Py, without requiring the actual “mypackage” dir to be in their PYTHONPATH? (Only the toplevel directory, e.g. site-packages, which contains “mypackage” should be in their PYTHONPATH.)

Thanks.

  • 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-27T18:33:57+00:00Added an answer on May 27, 2026 at 6:33 pm

    See http://docs.python.org/distutils/setupscript.html#installing-scripts

    The general idea is to distribute a setup.py file, such that when a user runs python setup.py install, the script gets placed on the path. Nearly all of the package distribution methods support this. If you follow the above documentation, users can easy_install, pip install etc. as their system allows.

    For an example in the wild, see https://github.com/django/django/blob/master/setup.py. There is a lot of configuration at the top of the file, but the important bit is at the bottom, where you can see

    setup(
        ...
        scripts = ['django/bin/django-admin.py'],
        ...
    )
    

    This sets up a django-admin.py command for users that install the django package. Once they install, they can run django-admin.py arg1 arg2 ... from their command line.

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

Sidebar

Related Questions

in python , suppose i have file data.txt . which has 6 lines of
Suppose I have a python script called my_parallel_script.py that involves using multiprocessing to parallelize
Suppose you have the following layout for a python package ./a ./a/__init__.py ./a/_b.py inside
Suppose I have a python object x and a string s , how do
Suppose I have a Python class that I want to add an extra property
I have embedded a Python interpreter in a C program. Suppose the C program
I have a python app which is supposed to be very long-lived, but sometimes
I want to know about timer in Python. Suppose i have a code snippet
Suppose a programmer has the following problem: he wants to start a new python
Suppose you have the following b b/__init__.py b/c b/c/__init__.py b/c/d b/c/d/__init__.py In some python

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.