Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why io module object has no attribute 'RawIOBase' eventhough I am using python 2.6

Tags:

python

I was trying to create a class in python with 'RawIOBase' as given below.

try:
    import io
except ImportError:
    class Serial(PosixSerial, FileLike):
        pass
else:
    class Serial(PosixSerial, io.RawIOBase):
        pass

I was trying to run this using Python 2.6, but it is displaying the error:

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

I read that RawIOBase is supported from Python 2.6 onwards.

like image 820
kadina Avatar asked Mar 20 '23 16:03

kadina


1 Answers

Make sure you do not have another file named io.py. If so, it could mask the io module in the standard library. You can check which file is getting loaded as the io module by printing print(io). It should return something like <module 'io' from '/usr/lib/python2.6/io.pyc'>.

If there is such a module or package masking the standard lib module, the solution is to rename the non-standard io module or package.

like image 64
unutbu Avatar answered Apr 28 '23 10:04

unutbu