1. ViciousRedBeam
  2. memcacheliked
  3. Pull requests

Pull requests

#2 Merged
Repository
msabramo
Branch
fix_relative_import_error
Repository
ViciousRedBeam
Branch
default

Fix "Attempted relative import in non-package" error

Author
  1. Marc Abramowitz
Reviewers
Description

Without this change, I get:

(py27.venv)marca@marca-mac:~/dev/hg-repos/memcacheliked$ python memcacheliked/sample.py
Traceback (most recent call last):
  File "memcacheliked/sample.py", line 23, in <module>
    from . import Memcacheliked, retrieval_command, storage_command, deletion_command, STORAGE_STATUS_STORED, DELETION_STATUS_DELETED, DELETION_STATUS_NOT_FOUND
ValueError: Attempted relative import in non-package
(py27.venv)marca@marca-mac:~/dev/hg-repos/memcacheliked$ cd memcacheliked
(py27.venv)marca@marca-mac:~/dev/hg-repos/memcacheliked/memcacheliked$ python sample.py
Traceback (most recent call last):
  File "sample.py", line 23, in <module>
    from . import Memcacheliked, retrieval_command, storage_command, deletion_command, STORAGE_STATUS_STORED, DELETION_STATUS_DELETED, DELETION_STATUS_NOT_FOUND
ValueError: Attempted relative import in non-package

With it, stuff works:

(py27.venv)marca@marca-mac:~/dev/hg-repos/memcacheliked$ python memcacheliked/sample.py
[2013/09/13 22:35:49] {diesel} WARNING:Starting diesel <libev/pyev (4/15) backend=select()>
  • Learn about pull requests

Comments (1)

  1. Marc Abramowitz author

    The current code with the relative import works when passing -m memcacheliked.sample to python; but not when passing the filename:

    vagrant@lucid64:~/dev/hg-repos/memcacheliked$ .tox/py26/bin/python -m memcacheliked.sample
    [2013/09/13 23:23:32] {diesel} WARNING:Starting diesel <hand-rolled select.epoll>
    ^C[2013/09/13 23:23:41] {diesel} WARNING:-- KeyboardInterrupt raised.. exiting main loop --
    [2013/09/13 23:23:41] {diesel} INFO:Ending diesel application
    vagrant@lucid64:~/dev/hg-repos/memcacheliked$ .tox/py26/bin/python memcacheliked/sample.py
    Traceback (most recent call last):
      File "memcacheliked/sample.py", line 23, in <module>
        from . import Memcacheliked, retrieval_command, storage_command, deletion_command, STORAGE_STATUS_STORED, DELETION_STATUS_DELETED, DELETION_STATUS_NOT_FOUND
    ValueError: Attempted relative import in non-package
    

    The change in this PR works with both:

    vagrant@lucid64:~/dev/hg-repos/memcacheliked$ .tox/py26/bin/python -m memcacheliked.sample
    [2013/09/13 23:47:24] {diesel} WARNING:Starting diesel <hand-rolled select.epoll>
    ^C[2013/09/13 23:47:26] {diesel} WARNING:-- KeyboardInterrupt raised.. exiting main loop --
    [2013/09/13 23:47:26] {diesel} INFO:Ending diesel application
    vagrant@lucid64:~/dev/hg-repos/memcacheliked$ .tox/py26/bin/python memcacheliked/sample.py
    [2013/09/13 23:47:29] {diesel} WARNING:Starting diesel <hand-rolled select.epoll>
    ^C[2013/09/13 23:47:33] {diesel} WARNING:-- KeyboardInterrupt raised.. exiting main loop --
    [2013/09/13 23:47:33] {diesel} INFO:Ending diesel application