I want to revisit the question as specified in PYTHONPATH vs. sys.path. Basically it is concerned with developing a package like:
Project
setup.py
package
__init__.py
lib.py
script.py
Assuming script.py
does from package.lib import foo
it does work when calling:
python -m package.script
from the directory where setup.py
is sitting, but not when calling (on windows, CPython 2.7):
.\package\script.py
ImportError: No module named package
In first case when printing sys.path
first entry is ''
, but in second case the first entry is the absolute path to where script.py
is sitting. And of course in that case it does not know anything about package
and the import fails. This will also be the case when double-clicking in Explorer.
The original stackoverflow question recommends package installation by setup.py develop
. However, in current setuptools 3.5 (I am aware+confused of the distutils/setuptools renaming) this option is not even documented (I have setuptools 3.4.x, but did not try it).
Can anyone point out to me what the recommended ("… only obvious way to do it …") procedere is on windows (for CPython 2.7 but also having Python 3 in mind) for double-clicking the file and having it work. Relative imports?