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 http://stackoverflow.com/questions/72852/how-to-do-relative-imports-in-python