Results 1 to 5 of 5

Thread: Python error: 'module' has no attribute

  1. #1
    dcop is offline Registered User
    Name: Diana Coppenbarger
    Organization: Laboratory for Laser Energetics
    Project: Python interface to digital camera service
    Join Date
    Sep 2011
    Posts
    3

    Python error: 'module' has no attribute

    I have a number of slice files that I've converted to Python using slice2py. One of the slice files looks like this:

    Code:
    module LLE
    {
    module DIS
    {
        interface DISAdmin
        {
            void doStuff();
        };
    };
    };
    I generated Python code and used --output-dir to write the files to a directory called MDIS. So, in MDIS, there are the generated .py files and a directory called LLE. Within LLE, there is a directory called DIS. I finally got the imports to work, but now when I call checkedCast() on DISAdminPrx, I get an error. The code looks like this:

    Code:
    import sys
    import Ice
    import MDIS
    
    properties = Ice.createProperties(sys.argv)
    properties.setProperty("Ice.Default.Locator","DISIceGrid/Locator:default -h dis-server1-lle.lle.rochester.edu -p 11010")
    id = Ice.InitializationData()
    id.properties = properties
    ic = Ice.initialize(sys.argv, id)
    
    # Create a proxy
    #
    obj = ic.stringToProxy("Control@EP.DIS.ControlAdapter");
    disadmin = MDIS.LLE.DIS.DISAdminPrx.checkedCast(obj);
    This is failing with the error:
    Code:
    'module' object has no attribute 'DISAdminPrx'
    I'm new at Python, but I thought I had followed the rules correctly. This is running with Ice 3.3.0 and Python 2.6.

  2. #2
    mes's Avatar
    mes
    mes is online now ZeroC Staff
    Name: Mark Spruiell
    Organization: ZeroC, Inc.
    Project: Ice Developer
    Join Date
    Feb 2003
    Location
    California
    Posts
    1,445
    Hi Diana,

    Welcome to the forum.

    If your intent is to wrap the generated code inside a Python package, the proper way to do this is by adding a metadata annotation to your Slice definitions. For example:

    Code:
    [["python:package:MDIS"]]
    module LLE
    {
    module DIS
    {
        interface DISAdmin
        {
            void doStuff();
        };
    };
    };
    Remove (or rename) your existing MDIS directory and run slice2py again (without the --output-dir option). Afterward, you should be able to do the following with no additional modifications:

    % python
    >>> import MDIS
    >>>


    Regards,
    Mark

  3. #3
    dcop is offline Registered User
    Name: Diana Coppenbarger
    Organization: Laboratory for Laser Energetics
    Project: Python interface to digital camera service
    Join Date
    Sep 2011
    Posts
    3
    Thank you for your reply, Mark.

    I did as you suggested and added [["python:package:DIS_Config"]] to my Ice files. I have another directory with other Ice files that these Ice files depend on and I added [["python:package:DataSlice"]] to those files and ran slice2py. Since we have a standard directory to put all of these python files, I also redirected the output to sub-directories in this location. So, we have
    Code:
    PYTHONPATH=/oudvmt/python
    and now in that directory, I have my project directory called "DIS_Config" and the additional code in the directory /DataSlice, each having their own python files. So the structure looks like this:
    Code:
    /oudvmt/python
        /DIS_Config
            DISAdmin_ice.py
            DISControl_ice.py
            DIS_ice.py
            /DIS_Config
        /DataSlice
            Attribute_ice.py
            DataSet_ice.py
            /DataSlice
    In my Python script, I added
    Code:
    sys.path.append("/oudvmt/python/DIS_Config")
    sys.path.append("/oudvmt/python/DataSlice")
    and ran the function
    Code:
    disadmin = DIS_Config.LLE.DIS.DISAdminPrx.checkedCast(obj)
    and I get the error:
    Code:
    Traceback (most recent call last):
      File "./disconfig", line 11, in <module>
        import DIS_Config
      File "/oudvmt/python/DIS_Config/DIS_Config/__init__.py", line 5, in <module>
        import DISAdmin_ice
      File "/oudvmt/python/DIS_Config/DISAdmin_ice.py", line 16, in <module>
        import DISControl_ice
      File "/oudvmt/python/DIS_Config/DISControl_ice.py", line 19, in <module>
        import DISAlign_ice
      File "/oudvmt/python/DIS_Config/DISAlign_ice.py", line 371, in <module>
        Align._op_getImage = IcePy.Operation('getImage', Ice.OperationMode.Idempotent, Ice.OperationMode.Idempotent, False, (), (), (((), _M_LLE.Data._t_DataSet),), None, (_M_DIS_Config.LLE.DIS._t_ReservedException, _M_DIS_Config.LLE.DIS._t_CommandFailedException))
    AttributeError: 'module' object has no attribute '_t_DataSet'
    I need to be able to break up these two directories in this fashion because other projects may use the same code and we don't want multiple copies of these files in our PYTHONPATH.

    Thanks.

    -Diana

  4. #4
    mes's Avatar
    mes
    mes is online now ZeroC Staff
    Name: Mark Spruiell
    Organization: ZeroC, Inc.
    Project: Ice Developer
    Join Date
    Feb 2003
    Location
    California
    Posts
    1,445
    It's difficult to diagnose this issue without seeing the Slice files. I noticed that the symbol mentioned in the error message, _M_LLE.Data._t_DataSet, does not have a top-level package, unlike your other definitions. Is this intentional, or are you missing a python:package annotation?

    Regards,
    Mark

  5. #5
    dcop is offline Registered User
    Name: Diana Coppenbarger
    Organization: Laboratory for Laser Energetics
    Project: Python interface to digital camera service
    Join Date
    Sep 2011
    Posts
    3
    I've just been told that we have a support contract with ZeroC so I'll package up my Slice files and python program and ship it off there. Thanks for pointing me in the right direction. I'm farther than I was 2 days ago!

    -Diana

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Python loadSlice import module issue
    By spsoni in forum Help Center
    Replies: 3
    Last Post: 09-02-2009, 12:56 PM
  2. Using clr:property with cs:attribute
    By JVerwey in forum Help Center
    Replies: 2
    Last Post: 01-23-2009, 02:42 PM
  3. Compile error using VERSION in module
    By ctennis in forum Bug Reports
    Replies: 1
    Last Post: 03-29-2006, 02:49 PM
  4. problem with cs:class attribute
    By kovacm in forum Bug Reports
    Replies: 7
    Last Post: 08-25-2005, 11:12 PM
  5. Replies: 4
    Last Post: 08-18-2005, 03:08 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •