Archived
This forum has been archived. Please start a new discussion on GitHub.
Python error: 'module' has no attribute
in Help Center
I have a number of slice files that I've converted to Python using slice2py. One of the slice files looks like this:
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:
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:
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:
'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.
0
Comments
-
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:[["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,
Mark0 -
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 havePYTHONPATH=/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:/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 addedsys.path.append("/oudvmt/python/DIS_Config") sys.path.append("/oudvmt/python/DataSlice")
and ran the functiondisadmin = DIS_Config.LLE.DIS.DISAdminPrx.checkedCast(obj)
and I get the error: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.
-Diana0 -
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,
Mark0 -
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!
-Diana0