Skip to content

Recursive load fails in Python 3.4 from macports #11

Open

Description

@csnook

The init.py contains the following line, which seems to be redundant with the any import that would invoke it:

from DynectDNS import DynectRest

The default Python 2.7 installation in Mac OS 10.10 handles this just fine, but Python 3.4 fails to import it with this error:

$ ./example.py
Traceback (most recent call last):
File "./example.py", line 3, in
from dynect.DynectDNS import DynectRest
File "/Users/csnook/Envs/dynctl/lib/python3.4/site-packages/dynect/init.py", line 5, in
from DynectDNS import DynectRest
ImportError: No module named 'DynectDNS'

example.py contains only the following:

!/usr/bin/env python

from dynect.DynectDNS import DynectRest

When I comment out the import in init.py, Python 3.4 handles it just fine, but I have no idea if that would break other configurations, since I assume that statement was probably put there for a reason.

Activity

  1. grantholly commented on Apr 22, 2016

    @grantholly
    Contributor

    This defect is also on Ubuntu / Debian and Python3.4.

    On Ubuntu 14.04 LTS here's how I reproduced this:

    $ virtualenv --python=python3 venv
    $ . venv/bin/activate
    $ pip install DynectDNS
    

    Note: This defect also shows up if you clone the github repo directly and use python setup.py install

    With the library installed, when you try to import it via

    Python 3.4.3 (default, Oct 14 2015, 20:28:29) 
    [GCC 4.8.4] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>>import DynectDNS
    or
    >>>from DynectDNS import DynectRest
    or
    >>>import dynect
    

    These all fail with the same import error:

    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/home/gholly/py-envs/venv/lib/python3.4/site-packages/dynect/__init__.py", line 5, in <module>
        from DynectDNS import DynectRest
    ImportError: No module named 'DynectDNS'
    

    Now viewing /home/gholly/py-envs/venv/lib/python3.4/site-packages/dynect/init.py here's the problem.

    /home/gholly/py-envs/venv/lib/python3.4/site-packages/dynect/init.py

    # sync with setup.py
    version = '0.1'
    version_info = (0, 1)
    
    from DynectDNS import DynectRest
    

    Python will try to search for DynectDNS, and does not find it in any of the directories of sys.path. However, it looks like the module intended to be loaded here /home/gholly/py-envs/venv/lib/python3.4/site-packages/dynect/DynectDNS.py is located in the same directory. If you change init.py to instead use relative loading, it properly loads the DynectDNS module in both Python 2.7 and 3.4.

    # sync with setup.py
    version = '0.1'
    version_info = (0, 1)
    
    from .DynectDNS import DynectRest
    

    The difference is very subtle, but the import statement includes a dot, telling init.py to load from the current directory rather than searching for a module in the directories in sys.path, where it is currently not found.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions