Hi,

I am gettitn error in the python scripts as shown below:

AttributeError: 'module' object has no attribute 'lib'


I have installed the package WxPython of 2.8 version and Python of version 2.6

Please help me out to resolve this error

Recommended Answers

All 11 Replies

Can you post the whole traceback ?

Thanks for viewing my post.

Traceback I am getting is as follows:

Traceback (most recent call last):
File "E:/Projects/iRobot/BBK&BiT/BBK Processor/callBBKProcessor.py", line 5, in <module>
import processing
File "E:\Projects\iRobot\BBK&BiT\BBK Processor\processing.py", line 17, in <module>
import SuiteBuilder
File "E:\Projects\iRobot\BBK&BiT\BBK Processor\SuiteBuilder.py", line 14, in <module>
(BuilderErrorEvent,EVT_BUILDER_ERROR) = wx.lib.newevent.NewEvent()
AttributeError: 'module' object has no attribute 'lib'


where callBBKProcessor.py, processing.py and SuiteBuilder.py are the custom scripts in our projects.

Thanks,
Eswari

Thanks for viewing my post.

Traceback I am getting is as follows:

Traceback (most recent call last):
File "E:/Projects/iRobot/BBK&BiT/BBK Processor/callBBKProcessor.py", line 5, in <module>
import processing
File "E:\Projects\iRobot\BBK&BiT\BBK Processor\processing.py", line 17, in <module>
import SuiteBuilder
File "E:\Projects\iRobot\BBK&BiT\BBK Processor\SuiteBuilder.py", line 14, in <module>
(BuilderErrorEvent,EVT_BUILDER_ERROR) = wx.lib.newevent.NewEvent()
AttributeError: 'module' object has no attribute 'lib'


where callBBKProcessor.py, processing.py and SuiteBuilder.py are the custom scripts in our projects.

Thanks,
Eswari

Perhaps add a statement import wx.lib . See

>>> import wx
>>> wx.lib
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'lib'
>>> import wx.lib
>>> wx.lib
<module 'wx.lib' from '/usr/lib64/python2.6/site-packages/wx-2.8-gtk2-unicode/wx/lib/__init__.py'>

Added import wx.lib statement to the script, but still getting the same error. please help me in resolving this issue. I am facing this from long back.

Thanks
Eshwari

Is "wx" declared somewhere else in the program, so you have one wx over-riding the other?. You will have to post some code for specific suggestions.

Added import wx.lib statement to the script, but still getting the same error

The same error implies that wx is not installed on that computer.

Use
import wx.lib.newevent

Thanks a lot, resolved the issue by using import statement as

import wx.lib.newevent.


Now we are getting different issue like

Traceback (most recent call last):
File "E:\BBK Processor\callBBKProcessor.py", line 6, in <module>
import processing
File "E:\BBK Processor\processing.py", line 14, in <module>
import SCI.R3SCI as sci
ImportError: No module named R3SCI


where SCI is the folder containing custom python scripts. In processing.py script we are trying to import R3SCI.py script that is there in SCI folder.Folder structure is as follows:


E:
----> BBK Processor (folder)
-----------> callBBKProcessor.py (script)
-----------> processing.py (script)
----> SCI (folder)
-----------> R3SCI.py (script)

I have added the SCI folder to the classpath of the java class from where callBBKProcessor.py is executed.

How to import the scripts that are there in the folder other than the parent folder.

Thanks
Eshwari

Thanks a lot, resolved the issue by using import statement as

import wx.lib.newevent.


Now we are getting different issue like

Traceback (most recent call last):
File "E:\BBK Processor\callBBKProcessor.py", line 6, in <module>
import processing
File "E:\BBK Processor\processing.py", line 14, in <module>
import SCI.R3SCI as sci
ImportError: No module named R3SCI


where SCI is the folder containing custom python scripts. In processing.py script we are trying to import R3SCI.py script that is there in SCI folder.Folder structure is as follows:


E:
----> BBK Processor (folder)
-----------> callBBKProcessor.py (script)
-----------> processing.py (script)
----> SCI (folder)
-----------> R3SCI.py (script)

I have added the SCI folder to the classpath of the java class from where callBBKProcessor.py is executed.

How to import the scripts that are there in the folder other than the parent folder.

Thanks
Eshwari

You need an empty file __init__.py in the SCI folder and use

from SCI import R3SCI as sci

You can also add initialization code in __init__.py, like

print("The SCI package is being imported.")

Thank you Gribouillis for your suggesstions.

Already this SCI folder had __init__.py scrpt with the code like

__all__ = ["SCIBase","R2SCI","R3SCI","ScrappySCI","ScoobaSCI","SerialSocket","Tests","lispUtils","SCI"]


So I tried by making it as empty script, but eventhen getting the same error.

Please help me in resolving this issue.

Thanks,
Eswari

The package directory is not on path or pythonpath. What is your need for Python? Did you consider Jython?

Thank you Gribouillis for your suggesstions.

Already this SCI folder had __init__.py scrpt with the code like

__all__ = ["SCIBase","R2SCI","R3SCI","ScrappySCI","ScoobaSCI","SerialSocket","Tests","lispUtils","SCI"]


So I tried by making it as empty script, but eventhen getting the same error.

Please help me in resolving this issue.

Thanks,
Eswari

If __init__.py exists, it does not need to be empty. Since you are importing from processing.py which is not in the root folder, you could use a relative import

# file processing.py
from .SCI import R3SCI as sci # notice the dot before SCI which goes up one folder

The other solution, as tonyjv said, is to store the SCI folder in a folder X referred to in your PYTHONPATH environment variable, or to store it in one of your 'site-packages' folders. This is the best solution if SCI is an independent module which could be used in other programs.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.