AttributeError: 'module' object has no attribute 'ST_SIZEGRIP' - python

I'm having a problem trying to run a software called pyPENELOPE. After install it perfectly, i've tried run the software and received the error
Traceback (most recent call last):
File "/usr/bin/pypenelope", line 6, in <module>
from penelopetools.gui.main import run
File "/usr/share/python-penelope/penelopetools/gui/main.py", line 52, in <module>
from wxtools.statusbar import EnhancedStatusBar
File "/usr/share/python-penelope/wxtools/statusbar.py", line 72, in <module>
class EnhancedStatusBar(wx.StatusBar):
File "/usr/share/python-penelope/wxtools/statusbar.py", line 74, in EnhancedStatusBar
def __init__(self, parent, id=wx.ID_ANY, style=wx.ST_SIZEGRIP,
AttributeError: 'module' object has no attribute 'ST_SIZEGRIP'
Searching, I found that the problem might be in this call in the code
import wx
and I need to put the lines
import wxversion
wxversion.select('2.8')
import wx
But then i've receive de the message
wxversion.select('2.8')
File "/usr/lib/python2.7/dist-packages/wxversion.py", line 144, in select
raise AlreadyImportedError("wxversion.select() must be called before wxPython is imported")
wxversion.AlreadyImportedError: wxversion.select() must be called before wxPython is imported
Calling wxversion.select('2.8') before the import wxversion i've received
File "/usr/share/python-penelope/wxtools/statusbar.py", line 48, in <module>
wxversion.select('2.8')
NameError: name 'wxversion' is not defined
So.... What can I do?

If, like me, you are using python3 for pyPENELOPE, you can remove the wxversion lines and instead change ST_SIZEGRIP to STB_SIZEGRIP and your code should compile.
Best of luck,
Bunny.

Related

can't make imports

my project can't make import idk why
the error is showing
seifahmed15#Ubuntu:~/Desktop/DAC-master$ python3 main.py
Traceback (most recent call last):
File "/home/seifahmed15/Desktop/DAC-master/main.py", line 2, in <module>
from user import create
File "/home/seifahmed15/Desktop/DAC-master/user.py", line 5, in <module>
import hcaptcha
File "/home/seifahmed15/Desktop/DAC-master/hcaptcha.py", line 6, in <module>
from seleniumwire.undetected_chromedriver import Chrome
File "/home/seifahmed15/.local/lib/python3.11/site-packages/seleniumwire/undetected_chromedriver/__init__.py", line 9, in <module>
from seleniumwire.webdriver import Chrome
File "/home/seifahmed15/.local/lib/python3.11/site-packages/seleniumwire/webdriver.py", line 13, in <module>
from seleniumwire import backend
File "/home/seifahmed15/.local/lib/python3.11/site-packages/seleniumwire/backend.py", line 4, in <module>
from seleniumwire.server import MitmProxy
File "/home/seifahmed15/.local/lib/python3.11/site-packages/seleniumwire/server.py", line 4, in <module>
from seleniumwire.handler import InterceptRequestHandler
File "/home/seifahmed15/.local/lib/python3.11/site-packages/seleniumwire/handler.py", line 5, in <module>
from seleniumwire import har
File "/home/seifahmed15/.local/lib/python3.11/site-packages/seleniumwire/har.py", line 11, in <module>
from seleniumwire.thirdparty.mitmproxy import connections
File "/home/seifahmed15/.local/lib/python3.11/site-packages/seleniumwire/thirdparty/mitmproxy/connections.py", line 9, in <module>
from seleniumwire.thirdparty.mitmproxy.net import tls, tcp
File "/home/seifahmed15/.local/lib/python3.11/site-packages/seleniumwire/thirdparty/mitmproxy/net/tls.py", line 43, in <module>
"SSLv2": (SSL.SSLv2_METHOD, BASIC_OPTIONS),
^^^^^^^^^^^^^^^^
AttributeError: module 'OpenSSL.SSL' has no attribute 'SSLv2_METHOD'. Did you mean: 'SSLv23_METHOD'?
i have reinstall python and tried to install pkg manually
i have searched on google and YouTube and i didn't find any thing
The console message below offers a bit more context on one issue, specifically on line 43:
File "/home/seifahmed15/.local/lib/python3.11/site-packages/seleniumwire/thirdparty/mitmproxy/net/tls.py", line 43, in <module>
"SSLv2": (SSL.SSLv2_METHOD, BASIC_OPTIONS),
^^^^^^^^^^^^^^^^
AttributeError: module 'OpenSSL.SSL' has no attribute 'SSLv2_METHOD'. Did you mean: 'SSLv23_METHOD'?
It looks like you may have a typo in the area below:
"SSLv2": (SSL.SSLv2_METHOD, BASIC_OPTIONS)
As the error message tells us:
'OpenSSL.SSL' has no attribute 'SSLv2_METHOD'. Did you mean: 'SSLv23_METHOD'?
You could try revising like below:
"SSLv2": (SSL.SSLv23_METHOD, BASIC_OPTIONS)
The other text in your console log appears to be showing the full stack trace - There may be an error elsewhere, but the error message you posted seems to be referencing that specific error on line 43.
The thread below may help a bit with handling the stack trace and debugging further:
Get exception description and stack trace which caused an exception, all as a string

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

I'm using MacOs with the PyCharm environment, and my project is set to use Python 2.7.10. Now, I have on the first line of my module the line:
import numpy as np
When I try to run my code, I get the following error:
/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 /{path to file}/numpy_exercise.py
Traceback (most recent call last):
File "/{path to file}/numpy_exercise.py", line 1, in module>
import numpy as np
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/__init__.py", line 169, in module>
from . import polynomial
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/polynomial/__init__.py", line 20, in module>
from .polynomial import Polynomial
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/polynomial/polynomial.py", line 68, in module>
from .polytemplate import polytemplate
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/polynomial/polytemplate.py", line 17, in module>
polytemplate = string.Template(''' AttributeError: 'module' object has no attribute 'Template'
(note that "module>" was actually in brackets from both sides but because it gets omitted that way I daleted the first bracket so you can see it)
Though in Python 3 it does not happens to me. I looked on the web but couldn't find anything. I have no clue of why this is happening. I'd be glad to get some of your help!
Thank you guys!

AttributeError: 'module' object has no attribute '[x]'

I am trying to make a script that moves all the .txt files in your desktop to desktop/org, the code is as follows:
import os
import shutil
userhome = os.path.expanduser('~')
src = userhome + '/Desktop/'
dst = src+ 'org/'
def main():
txtlist = os.listdir(src)
for file in txtlist:
sortFiles(file)
def sortFiles(file):
if file.endswith(".txt"):
shutil.move(src+file,dst)
main()
If I execute the .py I get this error: AttributeError: 'module' object has no attribute 'copy'. However, if I erase the last line "main()" and I import this script as a module in the python command line and I call .main() from there it works perfectly well. How can I make this work as a script?
Traceback (most recent call last):
File "C:\Python32\org.py", line 3, in <module>
import shutil
File "C:\Python32\lib\shutil.py", line 14, in <module>
import tarfile
File "C:\Python32\lib\tarfile.py", line 50, in <module>
import copy
File "C:\Python32\lib\copy.py", line 61, in <module>
from org.python.core import PyStringMap
File "C:\Python32\org.py", line 19, in <module>
main()
File "C:\Python32\org.py", line 12, in main
sortFiles(file)
File "C:\Python32\org.py", line 16, in sortFiles
shutil.move(src+file,dst)
AttributeError: 'module' object has no attribute 'move'
I am using python 3.2
Wow, that’s some bad luck. You can understand what’s going on when you look at the traceback:
Traceback (most recent call last):
File "C:\Python32\org.py", line 3, in <module>
import shutil
So, the first line that is being executed is import shutil. That’s where everything starts going wrong—which is suprising given that it’s a built-in module.
File "C:\Python32\lib\shutil.py", line 14, in <module>
import tarfile
File "C:\Python32\lib\tarfile.py", line 50, in <module
import copy
So shutil import tarfile, which imports copy.
File "C:\Python32\lib\copy.py", line 61, in <module>
from org.python.core import PyStringMap
And copy has this nice thing that tries to import PyStringMap from a module called org.python.core. Now, this module usually does not exist, which would cause copy to use some alternative code instead: PyStringMap = None.
The problem is, that there is something called org: Your own script, org.py. So what happens is that Python tries to find something called python.core.PyStringMap in your org.py. To be able to go that far, it needs to execute the script, including the main() call at the end:
File "C:\Python32\org.py", line 19, in <module>
main()
File "C:\Python32\org.py", line 12, in main
sortFiles(file)
File "C:\Python32\org.py", line 16, in sortFiles
shutil.copy(src+file,dst)
AttributeError: 'module' object has no attribute 'copy'
And that leads us to the shutil.copy line which is a call to the shutil module. As this is the module we are still importing (from the very first line!), its import hasn’t completely yet, so the copy function inside does not exist, causing the AttributeError.
This is a very unfortunate situation in which the naming of your script caused a circular import for something that doesn’t exist.
You can easily fix this by renaming your script into something else.

Python module import difference "string.maketrans"

I have come across a strange python module import issue.
When I trying to import the boilerpipe module,
from boilerpipe.extract import Extractor
I got this exception:
Original exception was:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/boilerpipe-1.2.0-py2.7.egg/boilerpipe/extract/ __init__.py", line 2, in <module>
import urllib2
File "/usr/lib/python2.7/urllib2.py", line 94, in <module>
import httplib
File "/usr/lib/python2.7/httplib.py", line 1140, in <module>
import ssl
File "/usr/lib/python2.7/ssl.py", line 58, in <module>
import textwrap
File "/usr/lib/python2.7/textwrap.py", line 40, in <module>
class TextWrapper:
File "/usr/lib/python2.7/textwrap.py", line 82, in TextWrapper
whitespace_trans = string.maketrans(_whitespace, ' ' * len(_whitespace))
AttributeError: 'module' object has no attribute 'maketrans'
I've searched over internet and saying that in Python 2.6 the 'str' module has been renamed to 'string' module. So this looks like some where in code library it didn't import "string" module properly.
Yet the really strange thing is, when I run the python code from home directory and run the same piece of code (either by using python shell or using python pyfile.py), it works fine! No more import error.
So I'm bit confusing. Can anyone give me any hint?
Thanks!
Some other script in sys.path is called "string.py" and is masking the stdlib module.
Double check to make sure that you don't have a file string.py that has been imported.
To debug this, put somewhere:
import sys
raise Exception("string module: %r" %(sys.modules.get("string"), ))
That will tell you what string module was imported (or if it shows None, no string module has been imported yet).

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

I am new to python.And i am learning the standard library.
Whenever i run the code below , it always raise the AttributeError...
And it seems like there is something wrong with the import command.
Also , i try to run it on the interactive interpreator,and it works just fine.
The sample code
import tempfile
import os
#temp = tempfile.TemporaryFile()
temp = tempfile.mktemp()
print "tempfile","=>",temp
file = open(temp,"w+b")
file.write("*" * 1000)
file.seek(0)
print len(file.read()),"byte"
file.close()
try:
os.remove(temp)
except OSError:
pass
The error output
Traceback (most recent call last):
File "tempfile.py", line 1, in <module>
import tempfile
File "/home/zhkzyth/codeRep/pytest/tempfile.py", line 5, in <module>
tempfile = tempfile.mktemp()
AttributeError: 'module' object has no attribute 'mktemp'
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/apport_python_hook.py", line 66, in apport_excepthook
from apport.fileutils import likely_packaged, get_recent_crashes
File "/usr/lib/python2.7/dist-packages/apport/__init__.py", line 1, in <module>
from apport.report import Report
File "/usr/lib/python2.7/dist-packages/apport/report.py", line 12, in <module>
import subprocess, tempfile, os.path, urllib, re, pwd, grp, os
File "/home/zhkzyth/codeRep/pytest/tempfile.py", line 5, in <module>
tempfile = tempfile.mktemp()
AttributeError: 'module' object has no attribute 'mktemp'
Original exception was:
Traceback (most recent call last):
File "tempfile.py", line 1, in <module>
import tempfile
File "/home/zhkzyth/codeRep/pytest/tempfile.py", line 5, in <module>
tempfile = tempfile.mktemp()
AttributeError: 'module' object has no attribute 'mktemp'
My enviroment
ubuntu12.04
python2.7
Did you name your own file tempfile.py? If so, rename it, delete all your *.pyc files, and try again.
PS: providing the actual text of the error with the traceback would tell us these things.
Trying to access an attribute that does not belong to a class or function in a module raises an AttributeError exception, the attribute might have been deprecated in a later version of the Python interpreter being used. I suggest you check the version of the Python you're running and make sure your dir(module) includes the attribute you're trying to use

Categories