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

The Archive Base Latest Questions

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

I have a simple python application where my directory structure is as follows: project/

  • 0

I have a simple python application where my directory structure is as follows:

  • project/
    • main.py
    • config.py
    • plugins/
      • plugin1
      • plugin2
      • …

Config.py only loads configuration files, it does not contain any configuration info in itself.

I now want to distribute this program, and I thought I’d use setuptools to do it. The file users are expected to use is main.py, so that one clearly goes into /usr/bin and the rest of the files go into /usr/share/project.

But there’s one problem: I would somehow need to tell main.py to look for config.py in the share directory. But I can’t really be sure where exactly the share directory is since that’s up to setuptools, right?

What’s the best practice when distributing Python-based applications?

  • 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-13T10:33:09+00:00Added an answer on May 13, 2026 at 10:33 am

    setuptools install your package in a location which is reachable from python i.e. you can import it:

    import project
    

    the problem raise when you do relative imports instead of absolute imports. if your main.py imports config.py it works because they live in the same directory. when you move your main.py to another location like /usr/bin or another location present in PATH environment variable, python try to import config.py from sys.path and not from your package dir. the solution is to use absolute import:

    from project import config
    

    now main.py is “movable”.

    another solution, which i prefer, is using automatic script creation offered by setuptools.

    instead of having your code in a

    if __name__ == "__main__":
        # here all your beautiful code
    

    statement, put your code in a function (main could be a good name):

    def main():
        # put your code here
    
    if __name__ == "__main__":    # not needed, just in case...
        main()
    

    now modify your setup.py:

    setup(
        # ...
        entry_points = {
            "console_scripts": [
                # modify script_name with the name you want use from shell
                # $ script_name [params]
                "script_name = project.main:main",
            ],
        }
    )
    

    that’s all. after an install setuptools will create a wrapper script which is callable from shell and that calls your main function. now main.py can live in your project directory and you don’t need anymore to move it in a bin/ directory. note that setuptools automatically puts this script in the bin/ directory relative to the installation prefix.

    es.

    python setup.py install --prefix ~/.local
    

    install your project package in

    ~/.local/lib/python<version>/site-packages/<package_name>
    

    and your script in

    ~/.local/bin/<script_name>
    

    so be sure that ~/.local/bin is present in your PATH env.

    more info at: http://peak.telecommunity.com/DevCenter/setuptools#automatic-script-creation

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

Sidebar

Ask A Question

Stats

  • Questions 380k
  • Answers 380k
  • 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 There are number of things you need to look into.… May 14, 2026 at 10:01 pm
  • Editorial Team
    Editorial Team added an answer This should do the trick although its untested: where cast(replace(vehicleId,'R','')… May 14, 2026 at 10:01 pm
  • Editorial Team
    Editorial Team added an answer When you draw things to the screen, you need to… May 14, 2026 at 10:01 pm

Trending Tags

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

Top Members

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.