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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T20:18:50+00:00 2026-05-12T20:18:50+00:00

I want to distribute my app on OSX (using py2app) and as a Debian

  • 0

I want to distribute my app on OSX (using py2app) and as a Debian package.

The structure of my app is like:

app/
     debian/
            <lots of debian related stuff>
     scripts/
             app
     app/
         __init__.py
         app.py
         mod1/
              __init__.py
              a.py
         mod2/
              __init__.py
              b.py

My setup.py looks something like:

from setuptools import setup
import os
import os.path

osname = os.uname()[0]

if osname == 'Darwin':
    APP = ['app/app.py']
    DATA_FILES = []
    OPTIONS = {'argv_emulation': True}

    setup(
        app=APP,
        data_files=DATA_FILES,
        options={'py2app': OPTIONS},
        setup_requires=['py2app'],
    )
elif osname == 'Linux':
        setup(
        name = "app",
        version = "0.0.1",
        description = "foo bar",
        packages = ["app", "app.mod1", "app.mod2"],
        scripts = ["scripts/app"],
        data_files = [
            ("/usr/bin", ["scripts/app"]),
       ]
    )

Then, in b.py (this is on OSX):

from app.mod2.b import *

I get:

ImportError: No module named mod2.b

So basically, mod2 can’t acccess mod1. On Linux there’s no problem, because the python module ‘app’ is installed globally in /usr/shared/pyshared. But on OSX the app will obviously be a self-contained .app thing built by py2app. I wonder if I approached this totally wrong, are there any best practices when distributing Python apps on OSX?

Edit: I also tried a hack like this in b.py:

from ..mod2.b import *

ValueError: Attempted relative import beyond toplevel package

Edit2: Seems to be related to this How to do relative imports in Python?

  • 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-12T20:18:51+00:00Added an answer on May 12, 2026 at 8:18 pm

    I’m not sure if this is the ‘best practice’ or not (I’ve not put much python software into proper distribution), but I would just make sure that the top-level app package was in sys.path. Something like putting the following into the top-level __init__.py:

    try:
        import myapp
    except ImportError:
        import sys
        from os.path import abspath, dirname, split
        parent_dir = split(dirname(abspath(__file__)))[0]
        sys.path.append(parent_dir)
    

    I think that should do the right thing in a cross platform way.

    EDIT: As kaizer.se points out this might not work in the __init__.py file, depending on how the code you’re invoking is getting executed. It would only work if that file is evaluated. The key is to make sure that the top-level package is in sys.path from some the code that actually is running.

    Often times, so that I an execute individual files inside of a package directly (for testing with the if __name__ eq '__main__' idiom), I’ll do something like place a statement:

    import _setup
    

    At the top of the individual file in question, and then create a file _setup.py which does the path munging as necessary. So, something like:

    package/
        __init__.py
        _setup.py
        mod1/
            __init__.py
            _setup.py
            somemodule.py
    

    If you import _setup from somemodule.py, that setup file can ensure that the top level package is in sys.path before the rest of the code in somemodule.py is evaluated.

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

Sidebar

Related Questions

I have a free android app that I want to now distribute as free
Here's the current situation I'm in: I want to distribute a binary app on
I am looking to distribute a symfony web app, but don't want to reveal
I want to distribute an iPhone app to the store and cannot find any
I want to distribute my .NET app via ClickOnce but I also need the
I want to distribute two versions of my app, the stable branch as well
I completed to develop my first app. Right now i want to distribute my
I want to distribute a swing app to my client. In that application two
I have an app that I want to distribute to 3.1.x devices, but I
I using a Visual Studio Installer Project to distribute my WPF app. I need

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.