Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueError: Attempted relative import in non-package #1

Closed
jdevera opened this issue Jul 15, 2014 · 1 comment
Closed

ValueError: Attempted relative import in non-package #1

jdevera opened this issue Jul 15, 2014 · 1 comment

Comments

@jdevera
Copy link

jdevera commented Jul 15, 2014

When I try to run python bootstrap from the root of the project, I get this error:

Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 162, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/home/jdevera/devel/github/python-cmdline-bootstrap/bootstrap/__main__.py", line 7, in <module>
    from .bootstrap import main
ValueError: Attempted relative import in non-package

Is this not one of the intended uses of this __main__.py file?

If I do python -m bootstrap then it works fine.

@jgehrcke
Copy link
Owner

Indeed, the __main__.py file becomes executed if providing a directory or a zip file (see https://docs.python.org/2/using/cmdline.html). However, as I understand, this really is equivalent to running python bootstrap/__main__.py. And we do not expect this to work (the error message is expected). Hence, yes, python -m bootstrap is the intended use of __main__.py, as noted down here: http://gehrcke.de/2014/02/distributing-a-python-command-line-application/.

Is this answer sufficient?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants